W3cubDocs

/Web APIs

ReadableStreamBYOBReader: releaseLock() method

The releaseLock() method of the ReadableStreamBYOBReader interface releases the reader's lock on the stream. After the lock is released, the reader is no longer active.

The reader will appear errored if the associated stream is errored when the lock is released; otherwise, the reader will appear closed.

If the reader's lock is released while it still has pending read requests then the promises returned by the reader's ReadableStreamBYOBReader.read() method are immediately rejected with a TypeError. Unread chunks remain in the stream's internal queue and can be read later by acquiring a new reader.

Syntax

js

releaseLock()

Parameters

None.

Return value

None (undefined).

Exceptions

TypeError

Thrown if the source object is not a ReadableStreamBYOBReader.

Examples

A trivial examples is shown below. A lock is created as soon as the reader is created on the stream.

js

const reader = stream.getReader({ mode: "byob" });
reader.releaseLock();

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
releaseLock 89 89 102 No 75 No 89 89 102 63 No 15.0
reject_pending_read_request
NoreleaseLock() throws if there are pending read requests (rather than pending read requests being rejected).
NoreleaseLock() throws if there are pending read requests (rather than pending read requests being rejected).
102 No
NoreleaseLock() throws if there are pending read requests (rather than pending read requests being rejected).
No
NoreleaseLock() throws if there are pending read requests (rather than pending read requests being rejected).
NoreleaseLock() throws if there are pending read requests (rather than pending read requests being rejected).
102
NoreleaseLock() throws if there are pending read requests (rather than pending read requests being rejected).
No
NoreleaseLock() throws if there are pending read requests (rather than pending read requests being rejected).

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/releaseLock