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 called but it "shouldn't" #130

Open
ip413 opened this issue Feb 9, 2018 · 2 comments
Open

Subscriber called but it "shouldn't" #130

ip413 opened this issue Feb 9, 2018 · 2 comments

Comments

@ip413
Copy link

ip413 commented Feb 9, 2018

Every subscriber, subscribed in the same "call stack" as published message, will be called. Although subscription took place after publish.

var ps  = require("pubsub-js");

ps.subscribe("x", () => {console.log("x0")});
ps.publish("x");
ps.subscribe("x", () => {console.log("x1")});
// x0
// x1

This behaviour won't take place if there isn't any subscriber for the same topic already:

var ps  = require("pubsub-js");

ps.publish("x");
ps.subscribe("x", () => {console.log("x1")});

or subscriptions "after publish" will be executed in timeout

var ps  = require("pubsub-js");

ps.subscribe("x", () => {console.log("x0")});
ps.publish("x");
setTimeout(() => {
    ps.subscribe("x", () => {console.log("x1")})
}, 0);

The problem could be solved by checking subscribers to call (during publish) not after timeout, but before.

@curiousercreative
Copy link

This appears to have some overlap with this older issue: #59

@ip413
Copy link
Author

ip413 commented Jun 26, 2018

Yep, this is the same thing.

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