Skip to content

once()

Attaches a one-time listener function to an event, allowing it to be called only the next time the event is emitted. After being called, the listener is automatically removed.

Example

typescript
instance.once("foo", () => {
  /* [...] */
});

Parameters

ParameterTypeDefaultDescription
eventstring | symbolThe event name. Expects an ESMitterEventName.
fnunknownThe function that will be called when the event is emitted.
contextunknownundefinedThe context to invoke the listener with.

Returns

TypeDescription
ESMitterThe ESMitter instance, allowing for method chaining.

Notes

  • The listener will be removed after it is called once.
  • For persistent listeners, use on() or addListener().