Skip to content

[WIP] events: add destroy

Calling ee.emit('error', error') on an event emitter is generally not a good practice. This introduces a destroy() method using the same logic used in streams, allowing an Event Emitter impl to provide proper cleanup before emitting an error event.

The emitter.destroy() and emitter.destroyed behavior may be customized by implementations but the implementation still ensures that error and close events are emitted in a consistent way.

Note that this causes the 'error' to be emitted on nextTick. There are some places in core where the emit('error') is expected to be sync (in zlib for instance). Migrating those to use this will be a semver-major, unfortunately.

Also note that destroy will always emit a 'close' event, which will be new to some EventEmitters and may conflict with others, which also means semver-major to migrate.

/cc @mcollina @mafintosh

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading