import type { Driver } from "@effect/core/io/Schedule" /** * Retries with the specified schedule, until it fails, and then both the * value produced by the schedule together with the last error are passed to * the recovery function. * * @tsplus static effect/core/io/Effect.Aspects retryOrElseEither * @tsplus pipeable effect/core/io/Effect retryOrElseEither */ export function retryOrElseEither( policy: Schedule, orElse: (e: E, out: A1) => Effect ): (self: Effect) => Effect> { return ( self: Effect ): Effect> => policy.driver.flatMap((driver) => retryOrElseEitherLoop(self, driver, orElse)) } function retryOrElseEitherLoop( self: Effect, driver: Driver, orElse: (e: E, out: A1) => Effect ): Effect> { return self.map(Either.right).catchAll((e) => driver.next(e).foldEffect( () => driver.last.orDie.flatMap((out) => orElse(e, out).map(Either.left)), () => retryOrElseEitherLoop(self, driver, orElse) ) ) }