import * as tsplus_module_1 from "@effect/core/stream/Stream/operations/runIntoHubScoped";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/fork";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/fill";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/excl-forEach";
import * as tsplus_module_5 from "@effect/core/io/Hub/operations/bounded";
import * as tsplus_module_6 from "@effect/core/io/Effect/operations/do";
import * as tsplus_module_7 from "@effect/core/io/Effect/operations/tap";
import * as tsplus_module_8 from "@effect/core/io/Effect/operations/map";
/**
 * Converts the stream to a managed list of queues. Every value will be
 * replicated to every queue with the slowest queue being allowed to buffer
 * `maximumLag` chunks before the driver is back pressured.
 *
 * Queues can unsubscribe from upstream by shutting down.
 *
 * @tsplus fluent ets/Stream broadcastedQueues
 */

export function broadcastedQueues_(self, n, maximumLag, __tsplusTrace) {
  return tsplus_module_8.map_(tsplus_module_7.tap_(tsplus_module_6.bind_(tsplus_module_6.bind_(tsplus_module_6.Do(), "hub", () => tsplus_module_5.bounded(maximumLag, __tsplusTrace), __tsplusTrace), "queues", ({
    hub
  }) => tsplus_module_4.collectAll(() => tsplus_module_3.fill(n, () => hub.subscribe), __tsplusTrace), __tsplusTrace), ({
    hub
  }) => tsplus_module_2.fork(tsplus_module_1.runIntoHubScoped_(self, () => hub, __tsplusTrace), __tsplusTrace), __tsplusTrace), ({
    queues
  }) => queues, __tsplusTrace);
}
/**
 * Converts the stream to a managed list of queues. Every value will be
 * replicated to every queue with the slowest queue being allowed to buffer
 * `maximumLag` chunks before the driver is back pressured.
 *
 * Queues can unsubscribe from upstream by shutting down.
 *
 * @tsplus static ets/Stream/Aspects broadcastedQueues
 */

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