| 905 | } |
| 906 | |
| 907 | const retryUpdate = <X, E, RIn>( |
| 908 | schedule: Schedule.Schedule<X, E, RIn>, |
| 909 | stateTag: Context.Tag<{ state: unknown }, { state: unknown }>, |
| 910 | error: E, |
| 911 | state: unknown |
| 912 | ): Layer.Layer<{ state: unknown }, E, RIn> => { |
| 913 | return fromEffect( |
| 914 | stateTag, |
| 915 | pipe( |
| 916 | Clock.currentTimeMillis, |
| 917 | core.flatMap((now) => |
| 918 | pipe( |
| 919 | schedule.step(now, error, state), |
| 920 | core.flatMap(([state, _, decision]) => |
| 921 | ScheduleDecision.isDone(decision) ? |
| 922 | core.fail(error) : |
| 923 | pipe( |
| 924 | Clock.sleep(Duration.millis(Intervals.start(decision.intervals) - now)), |
| 925 | core.as({ state }) |
| 926 | ) |
| 927 | ) |
| 928 | ) |
| 929 | ) |
| 930 | ) |
| 931 | ) |
| 932 | } |
| 933 | |
| 934 | /** @internal */ |
| 935 | export const scoped = dual< |