Web APIs

ReadableStreamDefaultReader.prototype.cancel()

Try the free JavaScript compiler

Requests cancellation of the associated readable stream and returns a promise for the cancellation result.

Formal Syntax & Structure

javascript syntaxjavascript
reader.cancel(reason)

Parameters & Attributes

NameTypeDescription
reasonanyOptional cancellation reason.

Return Value

Promise<undefined>

Requests cancellation of the associated readable stream and returns a promise for the cancellation result.

Working Example

Example Snippetjavascript
(async () => {let why;const s=new ReadableStream({cancel(r){why=r;}});const reader=s.getReader();await reader.cancel("stop");console.log(why,(await reader.read()).done);reader.releaseLock();})()
JavaScript Reference