Web APIs
ReadableStream.cancel()
Cancel an unlocked stream, discarding queued chunks and notifying its source. Use reader.cancel() if the stream is locked by a reader. Example console output: done.
Formal Syntax & Structure
javascript syntaxjavascript
stream.cancel([reason])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| reason | any | Cancellation reason. |
Return Value
Promise<undefined>
Completion of cancellation.
Working Example
Example Snippetjavascript
(async () => {let observed; const s=new ReadableStream({cancel(reason){observed=reason}}); await s.cancel("done"); console.log(observed);})()