Create a new event.
the parent that will be passed to listener as their this
Optionaloptions: AsyncEventOptions
options for this event
ReadonlysubscribablePublic AsyncSubscribable 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
Clear all listeners for this event.
Emit this event. This will invoke all of the listeners with the passed arguments. The listeners are invoked in order, and each listener is awaited before the next listener is invoked.
arguments that listeners will receive
promise that resolves when all listeners have handled the event, or rejects with the first error
Create a subscribable that will apply the specified filter to any listeners added.
filtered AsyncSubscribable
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 AsyncSubscribable
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
listener that resolves the next time the event is emitted
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. Resolves when the subscription is fully registered
Protectedsubscribe0Protectedunsubscribe0Create a Subscribable that changes the this argument used for listeners.
what should be treated as this for event listeners
modified AsyncSubscribable
An event that handles subscription in an asynchronous way.
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: