Cancel pending bridge work during shutdown

Reviewed By: mhorowitz

Differential Revision: D3381541

fbshipit-source-id: 51a3f766509ec78262792817dee3d5e6969ff05f
This commit is contained in:
Chris Hopman 2016-06-02 17:05:09 -07:00 committed by Facebook Github Bot 7
parent 68c11e55ee
commit db3adb4445
1 changed files with 4 additions and 1 deletions

View File

@ -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;
});
}