| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Schedule from "effect/Schedule"; |
| 3 | |
| 4 | /** |
| 5 | * Bounded 5-second poll (~3 minutes total) until `until` is satisfied. |
| 6 | * |
| 7 | * Explicitly annotated so the `Effect.repeat` conditional return type never |
| 8 | * survives into declaration emit (which would widen the provider layers of |
| 9 | * every `AWS.providers()` consumer — see processes/AWS/PATTERNS.md §7). |
| 10 | */ |
| 11 | export const pollBatch = <A, E, R>( |
| 12 | self: Effect.Effect<A, E, R>, |
| 13 | until: (a: A) => boolean, |
| 14 | ): Effect.Effect<A, E, R> => |
| 15 | Effect.repeat(self, { |
| 16 | schedule: Schedule.spaced("5 seconds"), |
| 17 | until, |
| 18 | times: 36, |
| 19 | }); |
| 20 | |
| 21 | /** |
| 22 | * Bounded retry (5s spacing, 10 tries) while the typed predicate holds. |
| 23 | * Same explicit-annotation rationale as {@link pollBatch}. |
| 24 | */ |
| 25 | export const retryBatch = <A, E extends { _tag: string }, R>( |
| 26 | self: Effect.Effect<A, E, R>, |
| 27 | while_: (e: E) => boolean, |
| 28 | times = 10, |
| 29 | ): Effect.Effect<A, E, R> => |
| 30 | Effect.retry(self, { |
| 31 | while: while_, |
| 32 | schedule: Schedule.max([ |
| 33 | Schedule.spaced("5 seconds"), |
| 34 | Schedule.recurs(times), |
| 35 | ]), |
| 36 | }); |