W3cubDocs

/Web APIs

ReadableStreamDefaultReader: releaseLock() method

The releaseLock() method of the ReadableStreamDefaultReader interface releases the reader's lock on the stream.

If the associated stream is errored when the lock is released, the reader will appear errored in that same way subsequently; 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 ReadableStreamDefaultReader.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 ReadableStreamDefaultReader.

Examples

js

function fetchStream() {
  const reader = stream.getReader();

  // ...

  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 78 79 65 No 65 ≤13.1 78 78 65 56 ≤13.4 12.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/ReadableStreamDefaultReader/releaseLock