Fabric: Removing sync block dispatching from `RCTRuntimeExecutorFromBridge`

Summary:
The purpose of RCTRuntimeExecutorFromBridge is to create/implement RuntimeExecutor using some JS queue implemented as part of the Bridge. This diff changes the implementation of this method, specifically:
Removing dispatching a sync block. This causes a deadlock with TM sometimes and should not be generally required.
The implementation does not retain the Bridge anymore.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D17960236

fbshipit-source-id: 0ddea561a6884f066e483d6b0f41ddd1621df73c
This commit is contained in:
Valentin Shergin 2019-10-24 17:43:08 -07:00 коммит произвёл Facebook Github Bot
Родитель 32b30074d3
Коммит b3cb27ee9f
1 изменённых файлов: 16 добавлений и 13 удалений

Просмотреть файл

@ -42,22 +42,25 @@ static ContextContainer::Shared RCTContextContainerFromBridge(RCTBridge *bridge)
static RuntimeExecutor RCTRuntimeExecutorFromBridge(RCTBridge *bridge)
{
RCTBridge *batchedBridge = [bridge batchedBridge] ?: bridge;
auto bridgeWeakWrapper = wrapManagedObjectWeakly([bridge batchedBridge] ?: bridge);
auto messageQueueThread = batchedBridge.jsMessageThread;
if (messageQueueThread) {
// Make sure initializeBridge completed
messageQueueThread->runOnQueueSync([] {});
}
RuntimeExecutor runtimeExecutor = [bridgeWeakWrapper](
std::function<void(facebook::jsi::Runtime & runtime)> &&callback) {
[unwrapManagedObjectWeakly(bridgeWeakWrapper) invokeAsync:[bridgeWeakWrapper, callback = std::move(callback)]() {
RCTCxxBridge *batchedBridge = (RCTCxxBridge *)unwrapManagedObjectWeakly(bridgeWeakWrapper);
auto runtime = (facebook::jsi::Runtime *)((RCTCxxBridge *)batchedBridge).runtime;
if (!batchedBridge) {
return;
}
RuntimeExecutor runtimeExecutor = [batchedBridge,
runtime](std::function<void(facebook::jsi::Runtime & runtime)> &&callback) {
// For now, ask the bridge to queue the callback asynchronously to ensure that
// it's not invoked too early, e.g. before the bridge is fully ready.
// Revisit this after Fabric/TurboModule is fully rolled out.
[((RCTCxxBridge *)batchedBridge) invokeAsync:[runtime, callback = std::move(callback)]() { callback(*runtime); }];
auto runtime = (facebook::jsi::Runtime *)(batchedBridge.runtime);
if (!runtime) {
return;
}
callback(*runtime);
}];
};
return runtimeExecutor;