Web APIs
ReadableStreamDefaultReader.prototype.cancel()
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
| Name | Type | Description |
|---|---|---|
| reason | any | Optional 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();})()