Closed
Description
Is this a bug report?
yes
Have you read the Contributing Guidelines?
yes
Environment
react-native -v
: 0.41node -v
: v6.9.5npm -v
: 4.6.1
- Target Platform: iOS
- Development Operating System: macOS
- Build tools: Xcode
Steps to Reproduce
Exported methods from a native module will reuse the same instance of RCTPromiseResolveBlock for every method defined in the module. Calling asynchronous methods at the same time will fail because RN only allows callbacks to be called once.
RCT_EXPORT_METHOD(foo:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter) {
// resolver to be called later on.
}
RCT_EXPORT_METHOD(bar:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter) {
// resolver to be called later on.
}
If we call those methods at the same time:
NativeModules.MyModule.foo().then(function(){console.log("foo")})
NativeModules.MyModule.bar().then(function(){console.log("bar")})
We then get this RN error:
Illegal callback invocation from native module.
This callback type only permits a single invocation from native code.
Debugging the app show the same instance of RCTPromiseResolveBlock is used in both calls. Is this expected?
Expected Behavior
Sequential async methods calls from a react native module should work. A new RCTPromiseResolveBlock instance should be created for every function call.
Actual Behavior
RCTPromiseResolveBlock instance is reused, not allowing more than one async function call at a time.