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

doc: emitter.removeListener within emit cycle clarification #4764

Closed
wants to merge 1 commit into from

Conversation

drjokepu
Copy link

As discussed in #4759, listeners removed from an event while the event's emit cycle is underway will still be called in that cycle and the new listener array will only be used in subsequent calls. This change updates the documentation to explicitly clarify this behaviour.

Listeners removed from an event while the event's emit
cycle is underway will still be called in that cycle and the
new listener array will only be used in subsequent calls.
This change updates the documentation to explicitly clarify this
behaviour.
@thefourtheye thefourtheye added doc Issues and PRs related to the documentations. events Issues and PRs related to the events subsystem / EventEmitter. labels Jan 19, 2016
@mscdex
Copy link
Contributor

mscdex commented Jan 19, 2016

The first line of the commit description (doc: ...) needs to be 50 characters or less.

Otherwise LGTM.

@@ -339,7 +339,8 @@ Removes the specified `listener` from the listener array for the specified
`removeListener` will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified `event`, then `removeListener` must be called
multiple times to remove each instance.
multiple times to remove each instance. Listeners removed from an event from
within the emit cycle of that event will still be called in that emit cycle.
Copy link
Contributor

Choose a reason for hiding this comment

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

The term emit cycle isn't defined anywhere, is it? It might be better to say that it will run all listeners attached at the time an event is emitted. This is sort of tricky to explain just in text, and a code example would be extremely helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would argue that a unit test to prove that this happens would be good too.

@jasnell
Copy link
Member

jasnell commented Jan 22, 2016

Agreed that a unit test would be good. I'm not sure if that behavior is intentional or accidental so if we're going to document it, we'd better make sure it doesn't change :-)

@drjokepu
Copy link
Author

The original bug at nodejs/node-v0.x-archive#7872 was closed because according to the person closing the bug this is the intended behaviour. I think that this behaviour is fairly non-trivial, so if it's indeed intended, it should be documented (and if isn't, it should be fixed).

The test is probably a good idea to ensure that this guarantee will be kept in the future.

@vaibhav93
Copy link
Contributor

@drjokepu Are you working on writing the test ? I wish to help if its not already done.

@drjokepu
Copy link
Author

@vaibhav93 I'm sorry, I've been rather busy with real life work the past few weeks and it unlikely that I'll have the time to look into this the next few weeks either, so if you have time and you would like to help, feel free to do it.

dirceu added a commit to dirceu/node that referenced this pull request Feb 12, 2016
@dirceu
Copy link
Contributor

dirceu commented Feb 12, 2016

@drjokepu I've created a new branch with the documentation fix + a code example + a test for it, but I'm not sure how to proceed. Should I open a new PR? Is there a way to add a commit to your PR?

@benjamingr
Copy link
Member

This has already been fixed in #5201 which was based on this, please feel free to open a new PR to add the test in @dirceu and thanks for the contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. events Issues and PRs related to the events subsystem / EventEmitter.
Projects
None yet
Development

Successfully merging this pull request may close these issues.