Skip to content

node:events

How Elide supports Node's events module: EventEmitter, once() and on() with an AbortSignal, captureRejections, and the EventEmitterAsyncResource and EventSource gaps.

On this page

node:events provides Node’s EventEmitter, once() and on() with an AbortSignal, once() on an EventTarget, captureRejections and EventEmitterAsyncResource.

Example

js
// events.mjs
import { EventEmitter, once } from "node:events";

const jobs = new EventEmitter();
jobs.on("done", (id) => console.log(`job ${id} done`));
jobs.emit("done", 1);

setTimeout(() => jobs.emit("idle", 3), 10);
const [pending] = await once(jobs, "idle");
console.log("idle with", pending, "listeners:", jobs.listenerCount("done"));
utf-8 · js · Lines: 10

elide run events.mjs prints:

text
job 1 done
idle with 3 listeners: 1
utf-8 · text · Lines: 2

Differences from Node

  • EventEmitterAsyncResource#asyncResource.eventEmitter does not return the emitter.
  • There is no EventSource global.

Reference

Status: Full · 34 of 38 suite tests pass (89.5%) · since 1.1.0

Exports

ExportKindStatusNotes
EventEmitterclassFulladdListener(), on(), once(), prependListener(), prependOnceListener(), removeListener(), off(), removeAllListeners(), emit(), listenerCount(), listeners(), rawListeners(), eventNames(), setMaxListeners(), getMaxListeners(), EventEmitter.defaultMaxListeners, EventEmitter.once(), EventEmitter.listenerCount()

Tests: node-api node:events: 34 pass, 3 fail, 1 error, 6 skipped. Failing: test-event-capture-rejections.js, test-eventemitter-asyncresource.js, test-events-once.js, test-eventsource.js.

Was this page helpful?