UNPKG

@prelude/channel

Version:

Channel module.

39 lines 954 B
import { Channel } from './channel.js'; export function of(cap = 0) { return new Channel(cap); } export function ofIterable(iterable, cap = 0) { const ch = new Channel(cap); const produce = async () => { for (const value of iterable) { if (ch.doneWriting) { break; } await Promise .resolve() .then(() => ch.write(value)); } }; produce() .finally(() => { ch.closeWriting(); }); return ch; } export function ofAsyncIterable(asyncIterable, cap = 0) { const ch = new Channel(cap); const produce = async () => { for await (const value of asyncIterable) { if (ch.doneWriting) { break; } await ch.write(value); } }; produce() .finally(() => { ch.closeWriting(); }); return ch; } //# sourceMappingURL=of.js.map