import * as tsplus_module_1 from "@effect/core/stream/Stream/operations/fromQueue";
import * as tsplus_module_2 from "@effect/core/stream/Stream/operations/scoped";
import * as tsplus_module_3 from "@effect/core/stream/Stream/operations/flatMap";
import * as tsplus_module_4 from "@effect/core/stream/Stream/operations/flattenTake";
import * as tsplus_module_5 from "@effect/core/stream/Stream/operations/broadcastedQueuesDynamic";
import * as tsplus_module_6 from "@effect/core/io/Effect/operations/map";
/**
 * Fan out the stream, producing a dynamic number 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 broadcastDynamic
 */

export function broadcastDynamic_(self, maximumLag, __tsplusTrace) {
  return tsplus_module_6.map_(tsplus_module_5.broadcastedQueuesDynamic_(self, maximumLag, __tsplusTrace), effect => tsplus_module_4.flattenTake(tsplus_module_3.flatMap_(tsplus_module_2.scoped(() => effect, __tsplusTrace), queue => tsplus_module_1.fromQueue(() => queue), __tsplusTrace), __tsplusTrace), __tsplusTrace);
}
/**
 * Fan out the stream, producing a dynamic number 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 broadcastDynamic
 */

export const broadcastDynamic = (maximumLag, __tsplusTrace) => self => broadcastDynamic_(self, maximumLag, __tsplusTrace);
//# sourceMappingURL=broadcastDynamic.mjs.map