import * as tsplus_module_1 from "@effect/core/stream/Stream/operations/fromQueueWithShutdown";
import * as tsplus_module_2 from "@effect/core/stream/Stream/operations/flattenTake";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/map";
import * as tsplus_module_4 from "@effect/core/stream/Stream/operations/broadcastedQueues";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/map";
/**
 * Fan out the stream, producing a list of streams that have the same elements
 * as this stream. The driver stream will only ever advance the `maximumLag`
 * chunks before the slowest downstream stream.
 *
 * @tsplus fluent ets/Stream broadcast
 */

export function broadcast_(self, n, maximumLag, __tsplusTrace) {
  return tsplus_module_5.map_(tsplus_module_4.broadcastedQueues_(self, n, maximumLag, __tsplusTrace), chunk => tsplus_module_3.map_(chunk, queue => tsplus_module_2.flattenTake(tsplus_module_1.fromQueueWithShutdown(() => queue), __tsplusTrace)), __tsplusTrace);
}
/**
 * Fan out the stream, producing a list of streams that have the same elements
 * as this stream. The driver stream will only ever advance the `maximumLag`
 * chunks before the slowest downstream stream.
 *
 * @tsplus static ets/Stream/Aspects broadcast
 */

export const broadcast = (n, maximumLag, __tsplusTrace) => self => broadcast_(self, n, maximumLag, __tsplusTrace);
//# sourceMappingURL=broadcast.mjs.map