Skip to content

events: support abortsignal in ee.on

An attempt to support passing a signal to EventEmitter's once in order to unsubscribe.

This is useful for ergonomically unsubscribing from multiple events at once.

This is very much WIP and should not be merged. It currently introduces a ±12% performance regression in the add/remove listeners benchmarks.

I am interested mostly in:

  • Discussion about the API - is this even a good idea? is there ecosystem breakage potential? Is there a better API for this?
  • People to possibly play around with it so we can figure out if this (and the EventTarget counterpart at https://github.com/whatwg/dom/issues/911 ) is a good idea.
  • Ideas on how to avoid the performance regression (swap out removeListener and addListener on the emitter when a signal is passed for the first time maybe?)

cc @nodejs/events @jasnell

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