Skip to content

API reference > @kontsedal/olas-core > Emitter

Emitter type ​

Synchronous fan-out event bus. Handlers run in the order they subscribed.

Emission iterates a SNAPSHOT of the handler set taken at the start ofemit(). So within one emission: a handler added during emit does NOT fire for the current emission, and a handler removed during emit STILL fires for the current emission (it was captured in the snapshot).

Handlers are stored in a Set keyed by reference — calling on(h) twice with the same h registers it ONCE; a single unsubscribe then removes it.

Emitter<void> exposes emit() (no argument); other shapes exposeemit(value: T).

Spec §7, §20.6.

Signature:

typescript
type Emitter<T> = {
  emit: [T] extends [void] ? () => void : (value: T) => void;
  on(handler: (value: T) => void): () => void;
  once(handler: (value: T) => void): () => void;
  dispose(): void;
};

Released under the MIT License.