Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Note: This feature is available in Web Workers.
The close() method of the ReadableStreamDefaultController interface closes the associated stream.
Readers will still be able to read any previously-enqueued chunks from the stream, but once those are read, the stream will become closed. If you want to completely get rid of the stream and discard any enqueued chunks, you'd use ReadableStream.cancel() or ReadableStreamDefaultReader.cancel().
None.
None (undefined).
Thrown if close() is called when the stream is not readable — because it is already closed, cancelled, or errored — or because it has been requested to close by the underlying source but it has not yet done so because there are still enqueued chunks to read.
In the following simple example, a custom ReadableStream is created using a constructor (see our Simple random stream example for the full code). The start() function generates a random string of text every second and enqueues it into the stream. A cancel() function is also provided to stop the generation if ReadableStream.cancel() is called for any reason.
When a button is pressed, the generation is stopped, the stream is closed using close(), and another function is run, which reads the data back out of the stream.
| Streams # ref-for-rs-default-controller-close① |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jun 23, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.