UNPKG

@prelude/channel

Version:

Channel module.

45 lines 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ofAsyncIterable = exports.ofIterable = exports.of = void 0; const channel_js_1 = require("./channel.js"); function of(cap = 0) { return new channel_js_1.Channel(cap); } exports.of = of; function ofIterable(iterable, cap = 0) { const ch = new channel_js_1.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; } exports.ofIterable = ofIterable; function ofAsyncIterable(asyncIterable, cap = 0) { const ch = new channel_js_1.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; } exports.ofAsyncIterable = ofAsyncIterable; //# sourceMappingURL=of.js.map