ReadableStream: locked property
The locked property indicates whether the stream is locked. A locked stream can't hand out another reader.
Value
A boolean.
true: a reader holds it, or it is being iterated byfor await, or itsResponsehas already been read in full by one of the four body-reading methods.false: not locked; you can callgetReader()or put it infor await.- Read-only. Assigning to it throws
TypeError. - It has no change event: the lock is taken by your own code. It goes back to
falsewhen the reader callsreleaseLock()or thefor awaitloop ends.
Examples
js
async function main() {
const res = new Response('abc');
if (res.body === null) return;
console.log(res.body.locked);
const reader = res.body.getReader();
console.log(res.body.locked);
reader.releaseLock();
console.log(res.body.locked);
}
main();Result: logs false, true, false in order.
Differences from the web
Same as the web.