Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit 651a453

Browse files
committed
Compute exponential by multiplying previous result
1 parent d82b23c commit 651a453

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

backoff/_wait_gen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def expo(
2222
"""
2323
# Advance past initial .send() call
2424
yield # type: ignore[misc]
25-
n = 0
25+
base_n: float = 1
2626
while True:
27-
a = factor * base ** n
27+
a = factor * base_n
2828
if max_value is None or a < max_value:
2929
yield a
30-
n += 1
30+
base_n *= base
3131
else:
3232
yield max_value
3333

tests/test_wait_gen.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ def test_expo_max_value():
6767
assert expect == next(gen)
6868

6969

70+
def test_expo_max_value_factor():
71+
gen = backoff.expo(factor=3, max_value=2 ** 4)
72+
gen.send(None)
73+
expected = [3 * 1, 3 * 2, 3 * 4, 16, 16, 16, 16]
74+
for expect in expected:
75+
assert expect == next(gen)
76+
77+
7078
def test_fibo():
7179
gen = backoff.fibo()
7280
gen.send(None)

0 commit comments

Comments
 (0)