Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// noprotect
async function streamingRead() {
  const response = await fetch('https://html.spec.whatwg.org');
  for await (const chunk of streamAsyncIterator(response.body)) {
    console.log(`Read ${chunk.length} bytes`);
  }
}
async function* streamAsyncIterator(stream) {
  // Get a lock on the stream
  const reader = stream.getReader();
  try {
    while (true) {
      // Read from the stream
      const {done, value} = await reader.read();
      // Exit if we're done
      if (done) return;
      // Else yield the chunk
      yield value;
    }
  }
  finally {
    reader.releaseLock();
  }
}
streamingRead();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jakearchibaldpro
0viewers