Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same RCTPromiseResolveBlock instance for different methods calls #15456

Closed
christophe-conceicao opened this issue Aug 10, 2017 · 1 comment
Closed
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@christophe-conceicao
Copy link

Is this a bug report?

yes

Have you read the Contributing Guidelines?

yes

Environment

  1. react-native -v: 0.41
  2. node -v: v6.9.5
  3. npm -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.

@christophe-conceicao
Copy link
Author

The bug was in my native module implementation. Was overriding the previous reference of RCTPromiseResolveBlock when calling a new method.

@facebook facebook locked as resolved and limited conversation to collaborators Aug 11, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants