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