// tracing: off
import { pipe } from "../../Function"
import * as Q from "../../Queue"
import * as T from "../_internal/effect"
import * as M from "../_internal/managed"
import { intoManaged_ } from "./intoManaged"
/**
 * Converts the stream to a managed queue of chunks. After the managed queue is used,
 * the queue will never again produce values and should be discarded.
 */

export function toQueue_(self, capacity) {
  return M.map_(
    M.tap_(
      M.bind_(M.do, "queue", () =>
        T.toManagedRelease_(Q.makeBounded(capacity), Q.shutdown)
      ),
      ({ queue }) => M.fork(intoManaged_(self, queue))
    ),
    ({ queue }) => queue
  )
}
/**
 * Converts the stream to a managed queue of chunks. After the managed queue is used,
 * the queue will never again produce values and should be discarded.
 */

export function toQueue(capacity) {
  return (self) => toQueue_(self, capacity)
}
//# sourceMappingURL=toQueue.js.map
