Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: There are two ways to make a NativeModule method execute synchronously: - Declare the NativeModule method to be synchronous (i.e: use `RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD`). - Make the NativeModule synchronous (i.e: make its method queue `RCTJSThread`). This way, all its methods are synchronous. `RCTNativeModule` executes all synchronous methods on the JS thread: - Executing an async methods on a sync module: https://git.io/JfRPj - Executing a sync method: https://git.io/JfRXe However, in TurboModules we block the JS thread, execute the method on the NativeModule's method queue, and then unblock the JS thread. While this approach is thread-safe, and arguably the correct way to dispatch sync methods, it's also much slower than the alternative. Therefore, this diff migrates the legacy behaviour to the TurboModule system. ## Special Case: getConstants() When an ObjC NativeModule requires main queue setup, and it exports constants, we execute its `constantsToExport` method on the main queue (see: [RCTModuleData gatherConstants](https://github.com/facebook/react-native/blob/c8d678abcf93fd3f6daf4bebfdf25937995c1fdf/React/Base/RCTModuleData.mm#L392-L402)). I replicated this behaviour with TurboModules. Changelog: [iOS][Fixed] - Execute ObjC TurboModule async method calls on JS thread for sync modules Reviewed By: fkgozali Differential Revision: D21602096 fbshipit-source-id: 42d07b7ad000abeac27091dc3ec440e3836d2eae
- Loading branch information