// ets_tracing: off import { pipe } from "../Function/index.js" import * as catchAll from "./catchAll.js" import * as core from "./core.js" import type { Effect } from "./effect.js" import * as fail from "./fail.js" import { zipRight_ } from "./zips.js" /** * Retries this effect until its error satisfies the specified effectful predicate. * * @ets_data_first retryUtilM_ */ export function retryUntilM( f: (a: E) => Effect, __trace?: string ) { return (self: Effect): Effect => retryUntilM_(self, f) } /** * Retries this effect until its error satisfies the specified effectful predicate. */ export function retryUntilM_( self: Effect, f: (a: E) => Effect, __trace?: string ): Effect { return core.suspend( () => pipe( self, catchAll.catchAll((e) => pipe( f(e), core.chain((b) => b ? fail.fail(e) : zipRight_(core.yieldNow, retryUntilM_(self, f)) ) ) ) ), __trace ) } /** * Retries this effect until its error satisfies the specified predicate. * * @ets_data_first retryUntil_ */ export function retryUntil(f: (a: E) => boolean, __trace?: string) { return (self: Effect) => retryUntil_(self, f, __trace) } /** * Retries this effect until its error satisfies the specified predicate. */ export function retryUntil_( self: Effect, f: (a: E) => boolean, __trace?: string ) { return retryUntilM_(self, (a) => core.succeed(f(a)), __trace) }