Effect fixes your TypeScript · Part 4
Your retry loop has 3 bugs
A hand-rolled retry loop retries errors that will never succeed, sleeps after the last attempt, and has no jitter. Effect.retry with a Schedule fixes all three in one expression: exponential, jittered, capped, and only for transient errors.
Comment below: How do you retry today?
Effect fixes your TypeScript: a series on the bugs you already ship, and how Effect makes them impossible. All code is real Effect v4 and was compiled before it went on screen. https://effect.website
Transcript
Your retry loop has a bug, probably three. The classic, a for loop, try, await, catch, sleep, double the delay, 30 lines. Bug one, it retries UserNotFound, which will never succeed. Bug two, it sleeps after the last attempt for nothing. Bug three, no jitter, so a thousand clients retry at the exact same millisecond. In Effect, Effect.retry with a Schedule, exponential from 100 millis, jittered, five times max, and only while the error is a DbError. One expression. The schedule is a value. Test it, reuse it, compose it. And the type still says UserNotFound can come out because we chose not to retry it. Best practice, retry only what's transient and make the policy a value, not a loop. Retrying one request is fine. Firing 10,000 at once is how you take down your own API. Part five, how do you retry today?




