Web APIs

ReadableStream()

Try the free JavaScript compiler

Create a stream backed by source callbacks or a supplied finite queue. Use pull and cancellation callbacks for producers that need demand-aware behavior. Example console output: item true.

Formal Syntax & Structure

javascript syntaxjavascript
new ReadableStream([underlyingSource[, strategy]])

Parameters & Attributes

NameTypeDescription
underlyingSourceobjectSource callbacks and optional byte-stream type.
strategyobjectQueuing strategy.

Return Value

ReadableStream

New readable stream.

Working Example

Example Snippetjavascript
(async () => {const s=new ReadableStream({start(c){c.enqueue("item");c.close()}}); const reader=s.getReader(); console.log((await reader.read()).value,(await reader.read()).done); reader.releaseLock();})()
JavaScript Reference