import * as Q from "../../../../Queue";
import * as CH from "../../Channel";
import * as TK from "../../Take";
import * as C from "../core";
import * as ToQueueUnbounded from "./toQueueUnbounded";
/**
 * Allows a faster producer to progress independently of a slower consumer by buffering
 * elements into an unbounded queue.
 */

export function bufferUnbounded(self) {
  const queue = ToQueueUnbounded.toQueueUnbounded(self);
  return new C.Stream(CH.managed_(queue, queue => {
    const process = CH.chain_(CH.fromEffect(Q.take(queue)), TK.fold(CH.end(undefined), error => CH.failCause(error), value => CH.zipRight_(CH.write(value), process)));
    return process;
  }));
}
//# sourceMappingURL=bufferUnbounded.js.map