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

events not called when removeListener used inside callback #125

Closed
john-dagger opened this issue Apr 19, 2022 · 0 comments · Fixed by #126
Closed

events not called when removeListener used inside callback #125

john-dagger opened this issue Apr 19, 2022 · 0 comments · Fixed by #126

Comments

@john-dagger
Copy link
Contributor

Im creating 2 separate message handlers for the same topic.
inside the first message handler it removes itself via removeListener() to imitate a once() call:

const mqEmitter = require('mqemitter');

function messageHandler1 (message, cb) {
  console.log('messageHandler1 called');
  // removes itself
  mqEmitter.removeListener('hello', messageHandler1);
  cb();
}

e.on('hello', messageHandler1)

function messageHandler2 (message, cb) {
  console.log('messageHandler2 called');
  cb();
}

mqEmitter.on('hello', messageHandler2);

mqEmitter.emit({ topic: 'hello' }, function () {
  console.log('emit callback called');
});

I would expect both of the handlers to be called and after that the emit callback.
so the expected output should be:

messageHandler1 called
messageHandler2 called
emit callback called

the second callback and the emit callback are newver called and the actual output is:

messageHandler1 called

I think the issue is that when emitting, fastparallel is given the same array instance that is used to hold (and remove for that matter) message handlers here: https://github.com/mcollina/mqemitter/blob/master/mqemitter.js#L121

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

Successfully merging a pull request may close this issue.

1 participant