Create a new event.
the parent that will be passed to listener as their this
Optionaloptions: EventOptions
options for creating this event
ReadonlysubscribablePublic Subscribable that can safely be shared with consumers that should be able to listen for events.
Get if there are any listeners available.
true if listeners are present
Get the number of listeners.
number of listeners
Emit this event asynchronously. This will invoke all of the listeners with the passed arguments. Triggering of the listeners will be done in order, waiting for a previous listener to finish before invoking the next one.
This method will not use the current ErrorStrategy and will instead reject if an error occurs.
arguments that the listeners will receive
Clear all listeners for this event.
Emit this event. This will invoke all of the listeners with the passed arguments. If a listener is asynchronous this method will use the current ErrorStrategy to handle errors, and will continue to trigger listeners while the listener is handling the event.
arguments that the listeners will receive
Create a subscribable that will apply the specified filter to any listeners added.
filtered Subscription
Create an iterator that supports async iteration of events emitted.
Optionaloptions: EventIteratorOptions
options for this iterator
iterable/iterator
Create a subscribable that changes the arguments of events before listeners receive them. The mapper returns the new arguments as an array, or a promise of the array:
const doubled = subscribable.map(n => [ n * 2 ]);
mapped Subscribable
Monitor for changes to listeners. The monitor is called after every subscribe, unsubscribe and clear. This is intended to be used to react to if listeners are currently registered. This can be used for things such as only listening to events from other objects when this event is active.
More than one monitor can be added. The same monitor is only added one time.
function used to monitor for changes to listeners
handle that removes the monitor, also with using
Get a promise that will resolve the first time this event is fired after this call.
Optionaloptions: OnceOptions
options, such as a signal that stops the wait
promise that resolves the next time the event is fired
Emit this event in parallel. This will invoke all of the listeners with the passed arguments. Triggering of the listeners will be done in parallel.
This method will not use the current ErrorStrategy. All listeners
are invoked, also if one of them fails. If one listener fails the promise
rejects with its error. If more than one listener fails the promise
rejects with an AggregateError that holds all of the errors.
arguments that the listeners will receive
Stop monitoring for listener changes.
Optionalmonitor: (event: this) => void
monitor to remove. If not given, all monitors are removed
Subscribe to this event using the given listener. The listener will be invoked any time the event is emitted. The returned handle can be used to unsubscribe.
listener to subscribe
Optionaloptions: SubscribeOptions
options for the subscription, such as a signal that unsubscribes
handle to the subscription, can be used to unsubscribe
Protectedsubscribe0Protectedunsubscribe0Create a subscribable that changes the this argument used for listeners.
what should be treated as this for event listeners
modified Subscribable
An event that handles subscription and fires its listeners in a synchronous fashion.
Each instance represents a single event:
The event can be emitted via the
emitmethod:Listeners can be added directly on the event, but it is recommended to use
.subscribablefor any API that is public:Listeners can be unsubscribed either via their handle or via the event:
Types are fully supported and especially useful when events are used in classes: