Streams

finished()

Observe stream completion or failure using the promise API. Local Node 22.16.0; production target compatibility pending. See https://nodejs.org/download/release/v22.16.0/docs/api/stream.html.

Formal Syntax & Structure

nodejs syntaxnodejs
finished(stream[, options])

Parameters & Attributes

NameTypeDescription
streamStreamStream whose completion is observed.
optionsobjectMonitoring options, including cleanup.

Return Value

Promise<void>

Result or receiver of the documented operation; see the linked versioned API contract.

Working Example

Example Snippetnodejs
import { Readable, Writable, Transform } from 'node:stream';import { pipeline, finished } from 'node:stream/promises';const source = Readable.from([1,2,3]);const check = new Transform({objectMode:true,transform(n,e,cb){if(n===2) cb(new Error('invalid item')); else cb(null,n);}});const sink = new Writable({objectMode:true,write(n,e,cb){cb();}});try { await pipeline(source,check,sink); } catch(e) { console.log(e.message, sink.destroyed); }
Node.js Reference