From db3adb4445785936501b5908e4bf7e60f10466f3 Mon Sep 17 00:00:00 2001 From: Chris Hopman Date: Thu, 2 Jun 2016 17:05:09 -0700 Subject: [PATCH] Cancel pending bridge work during shutdown Reviewed By: mhorowitz Differential Revision: D3381541 fbshipit-source-id: 51a3f766509ec78262792817dee3d5e6969ff05f --- ReactCommon/cxxreact/NativeToJsBridge.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index c7b665a55..4a935cf5b 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -312,12 +312,15 @@ ExecutorToken NativeToJsBridge::getTokenForExecutor(JSExecutor& executor) { void NativeToJsBridge::destroy() { m_delegate->quitQueueSynchronous(); auto* executorMessageQueueThread = getMessageQueueThread(m_mainExecutorToken); + // All calls made through runOnExecutorQueue have an early exit if + // m_destroyed is true. Setting this before the runOnQueueSync will cause + // pending work to be cancelled and we won't have to wait for it. + *m_destroyed = true; executorMessageQueueThread->runOnQueueSync([this, executorMessageQueueThread] { m_mainExecutor->destroy(); executorMessageQueueThread->quitSynchronous(); unregisterExecutor(*m_mainExecutor); m_mainExecutor = nullptr; - *m_destroyed = true; }); }