Skip to content

Commit

Permalink
Fix number of retries in retryN (#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
photomoose authored Dec 3, 2023
1 parent 1152a2c commit 9b5f72d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/ten-carpets-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Fix number of retries in retryN
2 changes: 1 addition & 1 deletion src/internal/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ const retryN_EffectLoop = <R, E, A>(
n: number
): Effect.Effect<R, E, A> => {
return core.catchAll(self, (e) =>
n < 0 ?
n <= 0 ?
core.fail(e) :
core.flatMap(core.yieldNow(), () => retryN_EffectLoop(self, n - 1)))
}
Expand Down
6 changes: 6 additions & 0 deletions test/Schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ describe.concurrent("Schedule", () => {
)
assert.strictEqual(result, "Error: 2")
}))
it.effect("retry exactly 'n' times after failure", () =>
Effect.gen(function*($) {
const ref = yield* $(Ref.make(0))
const result = yield* $(alwaysFail(ref), Effect.retryN(3), Effect.flip)
assert.strictEqual(result, "Error: 4")
}))
// TODO(Max): after TestRandom
// it.skip("for a given number of times with random jitter in (0, 1)")
// Effect.gen(function*(){
Expand Down

0 comments on commit 9b5f72d

Please sign in to comment.