Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
doc: emitter.removeListener within emit cycle clarification
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.
  • Loading branch information
tczinege authored and drjokepu committed Jan 19, 2016
commit 137ac35257cc64a2e0ced923dede97ed2d0beb8a
3 changes: 2 additions & 1 deletion doc/api/events.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy Markdown
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
Copy Markdown
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.


Because listeners are managed using an internal array, calling this will
change the position indices of any listener registered *after* the listener
Expand Down