Make main queue setup synchronous

Summary:
This can cause a deadlock if the main thread synchronously calls into some JS that creates a TurboModule. However, this is also the behaviour of legacy NativeModules. Furthermore, this also greatly simplifies how we'll fix async method invocation in TurboModules: T55255146.

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D20364251

fbshipit-source-id: d0db85665506f08c51c2f33a123e69960923e7f3
This commit is contained in:
Ramanpreet Nara
2020-03-10 19:59:33 -07:00
committed by Facebook Github Bot
parent 0c2db3256f
commit 1c1fa5b909
@@ -17,6 +17,7 @@
#import <React/RCTLog.h>
#import <React/RCTModuleData.h>
#import <React/RCTPerformanceLogger.h>
#import <React/RCTUtils.h>
#import <ReactCommon/TurboCxxModule.h>
#import <ReactCommon/TurboModuleBinding.h>
@@ -326,7 +327,14 @@ static Class getFallbackClassFromName(const char *name)
if ([[module class] respondsToSelector:@selector(requiresMainQueueSetup)] &&
[[module class] requiresMainQueueSetup]) {
dispatch_async(dispatch_get_main_queue(), setupTurboModule);
/**
* If the main thread synchronously calls into JS that creates a TurboModule,
* we could deadlock. This behaviour is migrated over from the legacy NativeModule
* system.
*
* TODO(T63807674): Investigate the right migration plan off of this
*/
RCTUnsafeExecuteOnMainQueueSync(setupTurboModule);
} else {
setupTurboModule();
}