"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.broadcastedQueues = void 0;
exports.broadcastedQueues_ = broadcastedQueues_;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Stream/operations/runIntoHubScoped"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/fork"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/fill"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/excl-forEach"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Hub/operations/bounded"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/do"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/tap"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/map"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * 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
 */
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
 */


const broadcastedQueues = (n, maximumLag, __tsplusTrace) => self => broadcastedQueues_(self, n, maximumLag, __tsplusTrace);

exports.broadcastedQueues = broadcastedQueues;
//# sourceMappingURL=broadcastedQueues.js.map