Skip to content

EventEmitter.once

Dragiyski edited this page Mar 28, 2015 · 2 revisions

This method adds a listener that is removed automatically after it has been called.

Usage

emitter.once(event, listener, dependencies)

Arguments

Argument Type Required Description
event string The name of the event.
listener function The listener function added for that event.
dependencies array or array-like object of functions List of dependencies for that listener.

Return

The this EventEmitter instance.

Exceptions

  • Throws a TypeError when listener is not a function.
  • Throws a TypeError when dependencies is array or array-like objects, but contain other than function.
  • Throws a ReferenceError when dependencies contain the listener (e.g. attempt to make listener dependency of itself).

Remarks

If a dependency is not added for as a listener for the given event, it'll be added as long as there are dependent listeners for it.

If listener already added for the specified event, following operation might happen:

  • If a listener is added as dependency by some early call, it'll be promoted to once listener. If listener is normal listener, it'll remain a normal listener.
  • If a list of dependencies is specified, it'll merged with current dependencies.

TODO

In case once called with listener that is already added as a normal listener, dependencies specified by once should be removed after the first call.

Clone this wiki locally