// ets_tracing: off
import * as CK from "../../../../Collections/Immutable/Chunk";
import * as Ex from "../../../../Exit";
import { pipe } from "../../../../Function";
import * as M from "../../../../Managed";
import * as O from "../../../../Option";
import * as Q from "../../../../Queue";
import * as CH from "../../Channel";
/*
 * Like `Stream#into`, but provides the result as a `Managed` to allow for scope
 * composition.
 */

export function runIntoElementsManaged_(self, queue) {
  const writer = () => CH.readWith(in_ => CH.zipRight_(CK.reduce_(in_, CH.unit, (channel, a) => CH.zipRight_(channel, CH.write(Ex.succeed(a)))), writer()), err => CH.write(Ex.fail(O.some(err))), _ => CH.write(Ex.fail(O.none)));

  return M.asUnit(CH.runManaged(CH.drain(CH.mapOutEffect_(self.channel[">>>"](writer()), _ => Q.offer_(queue, _)))));
}
/**
 * Like `Stream#into`, but provides the result as a `Managed` to allow for scope
 * composition.
 *
 * @ets_data_first runIntoElementsManaged_
 */

export function runIntoElementsManaged(queue) {
  return self => runIntoElementsManaged_(self, queue);
}
//# sourceMappingURL=runIntoElementsManaged.js.map