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

Messages published inside a subscriber won't be passed to uncached subscribers #178

Open
marrowleaves opened this issue Nov 6, 2017 · 0 comments

Comments

@marrowleaves
Copy link

I'm not sure if this is a postal bug or I'm using an anti-pattern. The problems is when I trying to publish the same topic with different data inside a subscriber function, only the invoked subscribers will received that new message. This only happens in the first time the subscriber get invoked.

code to reproduce:

var channel = postal.channel('settings');

channel.subscribe('update', function(data) {
    console.log('comp1', data)
});
channel.subscribe('update', function(data) {
    console.log('comp2', data)
    if (data.state === 'on')
        channel.publish('update', {
            color: 'green'
        })
});
channel.subscribe('update', function(data) {
    console.log('comp3', data)
});

channel.publish('update', {
    state: 'on'
});
channel.publish('update', {
    color: 'red'
});
channel.publish('update', {
    alignment: 'left'
});

Current result is:

comp1 {state: "on"}
comp2 {state: "on"}
comp1 {color: "green"}
comp2 {color: "green"}
comp3 {state: "on"}
comp1 {color: "red"}
comp2 {color: "red"}
comp3 {color: "red"}
comp1 {alignment: "left"}
comp2 {alignment: "left"}
comp3 {alignment: "left"}

comp3 didn't receive the message update {color: "green"}

while I'm expecting the following result(atomic publishing, maybe a message queue could help?):

comp1 {state: "on"}
comp2 {state: "on"}
comp3 {state: "on"}
comp1 {color: "green"}
comp2 {color: "green"}
comp3 {color: "green"}
comp1 {color: "red"}
comp2 {color: "red"}
comp3 {color: "red"}
comp1 {alignment: "left"}
comp2 {alignment: "left"}
comp3 {alignment: "left"}

or even the following result is acceptable(just make sure every message is delivered to every subscriber):

comp1 {state: "on"}
comp2 {state: "on"}
comp1 {color: "green"}
comp2 {color: "green"}
comp3 {color: "green"}
comp3 {state: "on"}
comp1 {color: "red"}
comp2 {color: "red"}
comp3 {color: "red"}
comp1 {alignment: "left"}
comp2 {alignment: "left"}
comp3 {alignment: "left"}

as I separate cache setup from invoking subscribers

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

1 participant