Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Use `time.monotonic` instead of `datetime.datetime.now` https://github.com/python-backoff/backoff/pull/23 (from @luccabb)
- Drop support for Python 3.7 https://github.com/python-backoff/backoff/pull/49 (from @edgarrmondragon)
- Improve performance of expo by multiplying previous result https://github.com/python-backoff/backoff/pull/50 (from @whonore)

## [v2.2.2] - 2025-11-17

Expand Down
6 changes: 3 additions & 3 deletions backoff/_wait_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def expo(
"""
# Advance past initial .send() call
yield # type: ignore[misc]
n = 0
base_n: float = 1
while True:
a = factor * base ** n
a = factor * base_n
if max_value is None or a < max_value:
yield a
n += 1
base_n *= base
else:
yield max_value

Expand Down
8 changes: 8 additions & 0 deletions tests/test_wait_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ def test_expo_max_value():
assert expect == next(gen)


def test_expo_max_value_factor():
gen = backoff.expo(factor=3, max_value=2 ** 4)
gen.send(None)
expected = [3 * 1, 3 * 2, 3 * 4, 16, 16, 16, 16]
for expect in expected:
assert expect == next(gen)


def test_fibo():
gen = backoff.fibo()
gen.send(None)
Expand Down
Loading