Skip to main content
Module

x/streamtools/channel.ts>channel

🦕 This is a Deno module that provides utilities for handling Streams API.
Latest
function channel
import { channel } from "https://deno.land/x/streamtools@v1.0.0/channel.ts";

Creates a new channel, which is a pair of a readable and writable stream.

import { channel } from "./channel.ts";
import { push } from "./push.ts";
import { pop } from "./pop.ts";

const { reader, writer } = channel<number>();

await push(writer, 1);
await push(writer, 2);
await push(writer, 3);
console.log(await pop(reader)); // 1
console.log(await pop(reader)); // 2
console.log(await pop(reader)); // 3

Type Parameters

T

The type of the elements that the channel can handle.

Parameters

optional
writableStrategy: QueuingStrategy<T>

The strategy for the writable side of the channel.

optional
readableStrategy: QueuingStrategy<T>

The strategy for the readable side of the channel.