// tracing: off
import { pipe } from "../../Function"
import * as M from "../_internal/managed"
import { broadcastedQueuesDynamic_ } from "./broadcastedQueuesDynamic"
import { flattenTake } from "./flattenTake"
import { fromQueueWithShutdown } from "./fromQueueWithShutdown"
/**
 * 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 of the `maximumLag` chunks before the
 * slowest downstream stream.
 */

export function broadcastDynamic_(self, maximumLag) {
  return M.map_(
    broadcastedQueuesDynamic_(self, maximumLag),
    M.map((_) => flattenTake(fromQueueWithShutdown(_)))
  )
}
/**
 * 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 of the `maximumLag` chunks before the
 * slowest downstream stream.
 */

export function broadcastDynamic(maximumLag) {
  return (self) => broadcastDynamic_(self, maximumLag)
}
//# sourceMappingURL=broadcastDynamic.js.map
