Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/proc/tests/deps/streams.ts>readerFromIterable

A high-level way to run child processes that is easy, flexible, powerful, and prevents resource leaks.
Go to Latest
function readerFromIterable
import { readerFromIterable } from "https://deno.land/x/proc@0.20.17/tests/deps/streams.ts";

Create a Reader from an iterable of Uint8Arrays.

     import { readerFromIterable } from "https://deno.land/std@0.224.0/streams/reader_from_iterable.ts";
     import { copy } from "https://deno.land/std@0.224.0/streams/copy.ts";

     const file = await Deno.open("metrics.txt", { write: true });
     const reader = 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);
       }
     })());
     await copy(reader, file);

Parameters

iterable: Iterable<Uint8Array> | AsyncIterable<Uint8Array>