diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm index 91fdbc9b329..83da4c8b50b 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm @@ -289,6 +289,30 @@ static Class getFallbackClassFromName(const char *name) } } + /** + * Some modules need their own queues, but don't provide any, so we need to create it for them. + * These modules typically have the following: + * `@synthesize methodQueue = _methodQueue` + */ + if ([module respondsToSelector:@selector(methodQueue)]) { + dispatch_queue_t methodQueue = [module performSelector:@selector(methodQueue)]; + if (!methodQueue) { + NSString *moduleClassName = NSStringFromClass(module.class); + NSString *queueName = [NSString stringWithFormat:@"com.facebook.react.%@Queue", moduleClassName]; + methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL); + @try { + [(id)module setValue:methodQueue forKey:@"methodQueue"]; + } @catch (NSException *exception) { + RCTLogError( + @"TM: %@ is returning nil for its methodQueue, which is not " + "permitted. You must either return a pre-initialized " + "queue, or @synthesize the methodQueue to let the bridge " + "create a queue for you.", + moduleClassName); + } + } + } + /** * Broadcast that this TurboModule was created. *