Download Latest Version v2.0.0 source code.zip (874.4 kB)
Email in envelope

Get an email when there's a new version of Emittery

Home / v2.0.0
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2026-03-04 3.2 kB
v2.0.0 source code.tar.gz 2026-03-04 868.2 kB
v2.0.0 source code.zip 2026-03-04 874.4 kB
Totals: 3 Items   1.7 MB 0

Breaking Changes

Listeners now receive a unified {name, data} object instead of raw data

All listeners (.on(), .onAny(), .once(), async iterators) now receive a single event object with name and data properties instead of the raw event data.

:::diff

- emitter.on('🦄', data => {
-   console.log(data);
+ emitter.on('🦄', ({data}) => {
+   console.log(data);
  });

For .onAny():

:::diff

- emitter.onAny((eventName, eventData) => {
-   console.log(eventName, eventData);
+ emitter.onAny(({name, data}) => {
+   console.log(name, data);
  });

For .once():

:::diff

- const data = await emitter.once('🦄');
+ const {data} = await emitter.once('🦄');

For .events() and .anyEvent() async iterators:

:::diff

- for await (const data of emitter.events('🦄')) {
+ for await (const {data} of emitter.events('🦄')) {
    console.log(data);
  }


- for await (const [eventName, eventData] of emitter.anyEvent()) {
+ for await (const {name, data} of emitter.anyEvent()) {
    …
  }

For predicates in .once():

:::diff

- emitter.once('data', data => data.ok === true);
+ emitter.once('data', ({data}) => data.ok === true);

emit() now throws AggregateError instead of rejecting with a single error

When multiple listeners throw, emit() now collects all errors into an AggregateError instead of silently dropping errors after the first one. All listeners always run to completion.

:::diff
  try {
    await emitter.emit('event');
  } catch (error) {

-   // error was from the first listener that threw
+   // error is an AggregateError with all listener errors in error.errors
+   console.log(error.errors);
  }

Requires Node.js 22

The minimum required Node.js version is now 22 (previously 14.16).

New Features

  • init/deinit lifecycle hooks - Register setup/teardown logic that runs when the first listener subscribes and the last listener unsubscribes for a given event.
  • Disposable support - Unsubscribe functions from .on() and .onAny() are now Disposable (usable with using for automatic cleanup).
  • AsyncDisposable support - Async iterators from .events() and .anyEvent() are now AsyncDisposable (usable with await using).
  • AbortSignal support for .events(), .anyEvent(), and .once() - Pass {signal} to cancel subscriptions externally.
  • .once() options object - Accepts {predicate, signal} in addition to a plain predicate function.
  • TC39 standard decorator support - Emittery.mixin() now works with both legacy and TC39 standard decorator syntax.

Bug Fixes

  • emit() no longer silently drops errors from multiple listeners
  • Debug logger no longer emits noise for internal meta events
  • Fixed emitMetaEvent breaking async emit() overrides in subclasses
  • Fixed Emittery not working when wrapped in a Proxy
  • Fixed mixin decorator to work with TC39 standard decorator syntax

https://github.com/sindresorhus/emittery/compare/v1.2.1...v2.0.0

Source: README.md, updated 2026-03-04