Skip to content

Commit

Permalink
bridge: emit message event inside a setImmediate
Browse files Browse the repository at this point in the history
Emit the bridge's message event inside a setImmediate, so listener
code is called outside the napi scope created when the bridge
receives a call from the react-native application code.
This allows for promises started on the listeners to be resolved and
causes errors to be recognized by the javascript engine instead of
silently failing.
  • Loading branch information
jaimecbernardo committed Oct 18, 2017
1 parent e5fbfd0 commit 70c9ac3
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ MyEmitter.prototype.send=function(msg) {
const channel = new MyEmitter();

var myListener = mybridgeaddon.registerListener( function(msg) {
channel.emit('message', msg);
setImmediate( () => {
channel.emit('message', msg);
});
});

exports.channel = channel;

0 comments on commit 70c9ac3

Please sign in to comment.