events.once()
A Node.js helper that returns a promise which resolves the next time an EventEmitter emits the named event.
In more detail
It turns an event into something you can await, as in await once(server, "listening"). It rejects if the emitter emits error first.
Related terms
- EventEmitter — The Node.js class for objects that emit named events and call registered listener functions, similar to the browser's EventTarget.
- Promise — A JavaScript object that stands for a result that is not ready yet and will later either succeed with a value or fail with an error.
- drain event — The event a Writable stream emits when its buffer has emptied after write() returned false, meaning it is safe to write again.
Taught in
- Writable Streams: Drain Events & highWaterMark — Node.js Internals & Backend Services
- Backpressure Engineering: Handling Mismatched I/O — Node.js Internals & Backend Services
- Native HTTP Server: Request & Response Lifecycles — Node.js Internals & Backend Services