/** * When the stream fails, retry it according to the given schedule * * This retries the entire stream, so will re-execute all of the stream's * acquire operations. * * The schedule is reset as soon as the first element passes through the * stream again. * * @param schedule Schedule receiving as input the errors of the stream. * * @tsplus static effect/core/stream/Stream.Aspects retry * @tsplus pipeable effect/core/stream/Stream retry */ export function retry( schedule: Schedule ) { return (self: Stream): Stream => Stream.unwrap( schedule.driver .map((driver) => { const loop: Stream = self.catchAll((e) => Stream.unwrap( driver.next(e).foldEffect( () => Effect.fail(e), () => Effect.sync(loop.tap(() => driver.reset)) ) ) ) return loop }) ) }