// ets_tracing: off
import * as A from "../../Collections/Immutable/Chunk";
import * as M from "../_internal/managed";
import { broadcastedQueues_ } from "./broadcastedQueues";
import { flattenTake } from "./flattenTake";
import { fromQueueWithShutdown } from "./fromQueueWithShutdown";
/**
 * Fan out the stream, producing a list of streams that have the same elements as this stream.
 * The driver stream will only ever advance of the `maximumLag` chunks before the
 * slowest downstream stream.
 */

export function broadcast(n, maximumLag) {
  return self => broadcast_(self, n, maximumLag);
}
/**
 * Fan out the stream, producing a list of streams that have the same elements as this stream.
 * The driver stream will only ever advance of the `maximumLag` chunks before the
 * slowest downstream stream.
 */

export function broadcast_(self, n, maximumLag) {
  return M.map_(broadcastedQueues_(self, n, maximumLag), A.map(q => flattenTake(fromQueueWithShutdown(q))));
}
//# sourceMappingURL=broadcast.js.map