import { pipe } from "../../Function"
import * as O from "../../Option"
import * as T from "../_internal/effect"
import * as M from "../_internal/managed"
import * as Ref from "../_internal/ref"
import * as Pull from "../Pull"
import { Stream } from "./definitions"
/**
 * Creates a stream from an effect producing chunks of `A` values until it fails with None.
 */

export function repeatEffectChunkOption(fa) {
  return new Stream(
    M.map_(
      M.let_(
        M.bind_(M.do, "done", () => Ref.makeManagedRef(false)),
        "pull",
        ({ done }) =>
          T.chain_(done.get, (b) =>
            b
              ? Pull.end
              : T.tapError_(
                  fa,
                  O.fold(
                    () => done.set(true),
                    () => T.unit
                  )
                )
          )
      ),
      ({ pull }) => pull
    )
  )
}
//# sourceMappingURL=repeatEffectChunkOption.js.map
