Web APIs

ReadableStream.cancel()

Try the free JavaScript compiler

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

NameTypeDescription
reasonanyCancellation 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);})()
JavaScript Reference