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

fix: handled case where event handler removed inside handler #126

Merged
merged 4 commits into from
May 23, 2022

Conversation

john-dagger
Copy link
Contributor

fixes #125

mqemitter.js Outdated
@@ -118,7 +118,7 @@ MQEmitter.prototype._do = function (message, callback) {
const matches = this._matcher.match(message.topic)

this.current++
this._parallel(this, matches, message, callback)
this._parallel(this, Array.from(matches), message, callback)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling that Array.from is slower than allocating an array of the same size and then use an old school for (;;) to copy over.

@john-dagger john-dagger requested a review from mcollina May 18, 2022 07:37
mqemitter.js Outdated
const matchesCopy = new Array(matches.length)
for (let i = 0, len = matches.length; i < len; i++) {
matchesCopy[i] = matches[i]
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will add too much overhead. Let's do the reverse: whenever removeListener() is called, a new array is allocated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok seems fair,
Im not sure how we'd implement that, because the array with the matched handlers is given to fastparallel in _do()
and the removeListener() is called within a matched handler that was called by fastparallel?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there is a better way: move the removal inside a setImmediate.

@john-dagger john-dagger requested a review from mcollina May 18, 2022 11:33
mqemitter.js Outdated
setImmediate(function () {
that._matcher.remove(topic, notify)
if (done) {
setImmediate(done)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the additional setImmediate here

@john-dagger john-dagger requested a review from mcollina May 19, 2022 07:38
Copy link
Owner

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 1d3837e into mcollina:master May 23, 2022
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 this pull request may close these issues.

events not called when removeListener used inside callback
2 participants