Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/msgpack_rpc/deps.ts>io.readerFromIterable

🦕 Deno module to support msgpack-rpc
Go to Latest
function io.readerFromIterable
import { io } from "https://deno.land/x/msgpack_rpc@v3.1.6/deps.ts";
const { readerFromIterable } = io;

Create a Deno.Reader from an iterable of Uint8Arrays.

     import { readerFromIterable } from "./streams.ts";
     import { serve } from "../http/server_legacy.ts";

     for await (const request of serve({ port: 8000 })) {
       // 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>