Skip to main content
Module

std/io/mod.ts>readerFromIterable

Deno standard library
Go to Latest
function readerFromIterable
import { readerFromIterable } from "https://deno.land/std@0.106.0/io/mod.ts";

Create a Deno.Reader from an iterable of Uint8Arrays.

 // Server-sent events: Send runtime metrics to the client every second.
 request.respond({
   headers: new Headers({ "Content-Type": "text/event-stream" }),
   body: readerFromIterable((async function* () {
     while (true) {
       await new Promise((r) => setTimeout(r, 1000));
       const message = `data: ${JSON.stringify(Deno.metrics())}\n\n`;
       yield new TextEncoder().encode(message);
     }
   })()),
 });

Parameters

iterable: Iterable<Uint8Array> | AsyncIterable<Uint8Array>