Create an Emitter
If a Stream is provided in the options, the Emitter will use it as
the stream to emit events to. In this case, the listeners
must also be
supplied.
If no Stream is provided, one will be created with the optional
allowedEvents
option.
If the event
option is specified, listeners will be registered by calling
Stream.on passing the event
option and the callback
option as
parameters.
options for creating the Emitter
A flag indicating whether the Emitter is closed
The listeners object mapping event names to arrays of callback functions
The stream that is used to register listeners
Close the emitter. This will emit a close
event.
No further events will be emitted.
the reason for closing the emitter. This can be of any type. The type of the close reason should be documented in the concrete implementation of the Stream that the emitter is linked to.
Emit an event.
When an event is emitted, all listeners registered with the Stream
for
this event will be called.
If the emitter is closed, or no event
is specified, nothing will be emitted.
Any additional arguments will be passed to the listeners.
the event name
arguments to pass to the listeners
Emit an event without checking if the emitter is closed.
the event name
arguments to pass to the listeners
Signal a error and close the emitter. This will emit an error
event and
subsequently a close
event. No further events will be emitted.
the error causing the emitter to close
Get the stream that is used to register the callbacks
the internal stream object
Process an event immediately.
Experimental.
Add a listener to all events
a callback function that will be called whenever an event is emitted. The event name will be passed as the first argument.
A single listener that will be called whenever an event is emitted. The event name will be passed as the first argument.
Create an emitter factory that can create an Emitter.
a list of allowed event names
a factory that creates an Emitter
An internal class to construct implementations of {@link events.Stream} with a privately scoped emit function.
This allows safe construction of event-based interfaces without exposing the means of emitting events.