Streams
stream/promises.finished()
Waits for the relevant stream sides to complete, or rejects on failure or premature closure. Use cleanup:true when you want the listeners installed by finished removed after settlement; this does not destroy a still-active stream. Tested on Node.js 22.16.0. Example output (one line per entry): ["true"].
Formal Syntax & Structure
nodejs syntaxnodejs
finished(stream[, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| stream | Stream | Stream being observed. |
| options | object | Completion sides, signal and cleanup settings. |
Return Value
Promise<void>
Completion notification.
Working Example
Example Snippetnodejs
import { Writable } from 'node:stream';import { finished } from 'node:stream/promises';const w = new Writable({ write(c, e, cb) { cb(); } });const done = finished(w, { cleanup: true });w.end('final');await done;console.log(w.writableFinished);