UNPKG

@johngw/stream

Version:

Reactive programming tools using the WHATWG Streams API.

47 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SinkComposite = void 0; const Async_1 = require("@johngw/stream-common/Async"); const Stream_1 = require("@johngw/stream-common/Stream"); /** * A collection of `UnderlyingSink`s that implement the `UnderlyingSink`. * * @group Sinks * @example * ``` * stream.pipeTo( * new WritableStream( * new SinkComposite([ * { write: (chunk) => console.info(`1 ${chunk}`) }, * { write: (chunk) => console.info(`2 ${chunk}`) }, * ]) * ) * ) * ``` */ class SinkComposite { #abortableSinks; #closableSinks; #startableSinks; #writableSinks; constructor(sinks) { this.#abortableSinks = sinks.filter(Stream_1.isAbortableSink); this.#closableSinks = sinks.filter(Stream_1.isClosableSink); this.#startableSinks = sinks.filter(Stream_1.isStartableSink); this.#writableSinks = sinks.filter(Stream_1.isWritableSink); } async abort(reason) { await (0, Async_1.all)(this.#abortableSinks, (sink) => sink.abort(reason)); } async close() { await (0, Async_1.all)(this.#closableSinks, (sink) => sink.close()); } async start(controller) { await (0, Async_1.all)(this.#startableSinks, (sink) => sink.start(controller)); } async write(chunk, controller) { await (0, Async_1.all)(this.#writableSinks, (sink) => sink.write(chunk, controller)); } } exports.SinkComposite = SinkComposite; //# sourceMappingURL=SinkComposite.js.map