Skip to content

Commit

Permalink
add __iter__ and __aiter__ docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Anvil committed Dec 17, 2023
1 parent 7bbde0c commit 97045a9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kaioretry/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class Context:
:raises ValueError: if tries, min_delay or max_delay have incorrect values.
.. automethod:: __iter__
.. automethod:: __aiter__
"""

DEFAULT_LOGGER: Final[logging.Logger] = logging.getLogger(__name__)
Expand Down Expand Up @@ -231,10 +234,20 @@ def __make_iterator(
self.__update_delay, self.__logger))

def __iter__(self) -> Generator[None, None, None]:
"""Returns a generator that perform sleep (using regular
:py:func:`time.sleep`) between iterations in order to induce delay as
instructed.
"""
yield
yield from self.__make_iterator(time.sleep)

async def __aiter__(self) -> AsyncGenerator[None, None]:
"""Returns a asynchronous generator that perform sleep through
:py:func:`asyncio.sleep` between iterations in order to induce delay
as instructed.
"""
yield
for sleep in self.__make_iterator(asyncio.sleep):
await sleep
Expand Down

0 comments on commit 97045a9

Please sign in to comment.