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

Subscriber callback method can brake calling other subscribers #174

Open
nikoskalogridis opened this issue Jul 10, 2017 · 1 comment
Open

Comments

@nikoskalogridis
Copy link

If a subscriber callback throws an Error the rest of the subscribers are not called. I think postal should guard the execution of the callbacks and if one throws it does not affect calling the other callbacks

import postal from 'postal';
const myChannel = postal.channel('my-channel');

function maliciousCallback() {
  throw new Error('sorry');
}

function cb(data) {
  console.log('hello ' + data);
}

myChannel.subscribe('*', maliciousCallback);
myChannel.subscribe('*', cb);

myChannel.publish('whatever', 'world');

in the example above the cb function is never called. One way to solve this would be to call the callbacks in a setTimeout(cb, 0); or in a try {} catch () {} block

@samvloeberghs
Copy link

samvloeberghs commented Jan 31, 2018

@nikoskalogridis what happened with this? I seem to run into similar issues.
I tried your example, but that is working fine tough ( postaljs v2.0.5 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants