drain event
The event a Writable stream emits when its buffer has emptied after write() returned false, meaning it is safe to write again.
In more detail
A producer that respects backpressure stops writing on false and resumes on drain, often with await once(stream, "drain"). Writing more before drain arrives is allowed, but the extra data just piles up in memory.
Related terms
- Writable stream — A Node.js stream you write data to, such as a file being written, an HTTP response or a socket.
- backpressure — A slow consumer signalling a fast producer to pause, so data does not pile up in memory faster than it can be handled.
- events.once() — A Node.js helper that returns a promise which resolves the next time an EventEmitter emits the named event.
Taught in
- Writable Streams: Drain Events & highWaterMark — Node.js Internals & Backend Services
- Backpressure Engineering: Handling Mismatched I/O — Node.js Internals & Backend Services