Web Streams
ReadableStreamDefaultReader.cancel()
Signals that the consumer no longer needs data. The underlying source can release its owned resources. Tested on Node.js 22.16.0. Example output (one line per entry): ["limit true"].
Formal Syntax & Structure
nodejs syntaxnodejs
reader.cancel([reason])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| reason | unknown | Cancellation reason. |
Return Value
Promise<void>
Cancellation completion.
Working Example
Example Snippetnodejs
let reason;const r = new ReadableStream({ cancel(v) { reason = v; } }).getReader();try { await r.cancel('limit'); console.log(reason, (await r.read()).done);}finally { r.releaseLock();}