// tracing: off
import * as C from "../../Cause"
import * as O from "../../Option"
import * as Q from "../../Queue/core"
import * as T from "../_internal/effect"
import * as M from "../_internal/managed"
import * as TK from "../Take"
/**
 * Like `into`, but provides the result as a `Managed` to allow for scope
 * composition.
 */

export function intoManaged_(stream, queue) {
  return M.chain_(stream.proc, (as) => {
    const go = T.foldCauseM_(
      as,
      (o) =>
        O.fold_(
          C.sequenceCauseOption(o),
          () => T.asUnit(Q.offer_(queue, TK.end)),
          (c) => T.zipRight_(Q.offer_(queue, TK.halt(c)), go)
        ),
      (a) => T.zipRight_(Q.offer_(queue, TK.chunk(a)), go)
    )
    return M.asUnit(T.toManaged(go))
  })
}
/**
 * Like `into`, but provides the result as a `Managed` to allow for scope
 * composition.
 */

export function intoManaged(queue) {
  return (self) => intoManaged_(self, queue)
}
//# sourceMappingURL=intoManaged.js.map
