@johngw/stream
Version:
Reactive programming tools using the WHATWG Streams API.
40 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SourceComposite = void 0;
const Async_1 = require("@johngw/stream-common/Async");
const Stream_1 = require("@johngw/stream-common/Stream");
/**
* A collection of `UnderlyingSource`s that implement the `UnderlyingSource`.
*
* @group Sources
* @example
* ```
* new ReadableStream(
* new SourceComposite([
* { start: (controller) => controller.enqueue('Hello') },
* { start: (controller) => controller.enqueue('World') },
* ])
* )
* ```
*/
class SourceComposite {
#cancellableSources;
#pullableSources;
#startableSources;
constructor(sources) {
this.#cancellableSources = sources.filter(Stream_1.isCancellableSource);
this.#pullableSources = sources.filter(Stream_1.isPullableSource);
this.#startableSources = sources.filter(Stream_1.isStartableSource);
}
async cancel(reason) {
await (0, Async_1.all)(this.#cancellableSources, (source) => source.cancel(reason));
}
async pull(controller) {
await (0, Async_1.all)(this.#pullableSources, (source) => source.pull(controller));
}
async start(controller) {
await (0, Async_1.all)(this.#startableSources, (source) => source.start(controller));
}
}
exports.SourceComposite = SourceComposite;
//# sourceMappingURL=SourceComposite.js.map