From 64825389dfb4e01d5b30cd63b0b41937a9bb431d Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 13 Jun 2017 09:30:36 -0700 Subject: [PATCH] Fix timers not firing when running in JS debugger Reviewed By: mhorowitz Differential Revision: D5227125 fbshipit-source-id: 3dadb3f2e2fd088853537c09cc019d7be6319444 --- React/CxxBridge/RCTObjcExecutor.mm | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/React/CxxBridge/RCTObjcExecutor.mm b/React/CxxBridge/RCTObjcExecutor.mm index 2b70c15fe..0a90fb217 100644 --- a/React/CxxBridge/RCTObjcExecutor.mm +++ b/React/CxxBridge/RCTObjcExecutor.mm @@ -16,6 +16,7 @@ #import #import #import +#import #import #import @@ -32,11 +33,14 @@ public: class RCTObjcExecutor : public JSExecutor { public: - RCTObjcExecutor(id jse, RCTJavaScriptCompleteBlock errorBlock, - std::shared_ptr delegate) + RCTObjcExecutor(id jse, + RCTJavaScriptCompleteBlock errorBlock, + std::shared_ptr jsThread, + std::shared_ptr delegate) : m_jse(jse) , m_errorBlock(errorBlock) - , m_delegate(delegate) + , m_jsThread(std::move(jsThread)) + , m_delegate(std::move(delegate)) { m_jsCallback = ^(id json, NSError *error) { if (error) { @@ -44,14 +48,16 @@ public: return; } - m_delegate->callNativeModules(*this, [RCTConvert folly_dynamic:json], true); + m_jsThread->runOnQueue([this, json]{ + m_delegate->callNativeModules(*this, [RCTConvert folly_dynamic:json], true); + }); }; // Synchronously initialize the executor [jse setUp]; folly::dynamic nativeModuleConfig = folly::dynamic::array; - auto moduleRegistry = delegate->getModuleRegistry(); + auto moduleRegistry = m_delegate->getModuleRegistry(); for (const auto &name : moduleRegistry->moduleNames()) { auto config = moduleRegistry->getConfig(name); nativeModuleConfig.push_back(config ? config->config : nullptr); @@ -120,7 +126,8 @@ public: private: id m_jse; RCTJavaScriptCompleteBlock m_errorBlock; - std::shared_ptr m_delegate; + std::shared_ptr m_delegate; + std::shared_ptr m_jsThread; RCTJavaScriptCallback m_jsCallback; }; @@ -135,7 +142,7 @@ std::unique_ptr RCTObjcExecutorFactory::createJSExecutor( std::shared_ptr delegate, std::shared_ptr jsQueue) { return std::unique_ptr( - new RCTObjcExecutor(m_jse, m_errorBlock, delegate)); + new RCTObjcExecutor(m_jse, m_errorBlock, jsQueue, delegate)); } }