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

Topic with more than one, same or different, callbacks #32

Open
GHNewbiee opened this issue Jul 13, 2023 · 0 comments
Open

Topic with more than one, same or different, callbacks #32

GHNewbiee opened this issue Jul 13, 2023 · 0 comments

Comments

@GHNewbiee
Copy link

Hi,

As per doc :

const pubsub = new PubSub();

pubsub.subscribe('message', listener);
pubsub.subscribe('message', listener);
pubsub.subscribe('another_message', listener);
  • What is the purpose of subscribing the same callback (listener) more than one to a topic?

Considering that the second callback is different (eg listener2), like

const pubsub = new PubSub();

pubsub.subscribe('message', listener1);
pubsub.subscribe('message', listener2);

or as per doc

const pubsub = new PubSub();

pubsub.subscribe('message', listener1);
pubsub.subscribeOnce('message', listener2);
pubsub.subscribe('another_message', listener1);
  • How do you decide which callback (listener1 or listener2) is called when publish or publishSync accepts as argument only the topic and not the token by means of which a specific callback could be used, eg
const pubsub = new PubSub();

const token1 = pubsub.subscribe('message', listener1)
const token2 = pubsub.subscribe('message', listener2)
const token3 = pubsub.subscribeOnce('message', listener3);

pubsub.publish(token1, data1);
pubsub.publish(token2, data2);
pubsub.publish(token3, data3);

Tia

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