limits icon indicating copy to clipboard operation
limits copied to clipboard

Feature request: `wait_for_hit`

Open aebrahim opened this issue 4 months ago • 0 comments

Hi - this is a really great library, and I think a new API function would make this easier to use for folks trying to use it in servers, like us.

Right now, the main mechanism we have to use in our application logic is the following:

# Using sync with threading
while not strategy.hit(limit):
    time.sleep(some_undefined_amount_of_time)

# Using async
while not await strategy.hit(limit):
    await asyncio.sleep(some_undefined_amount_of_time)

Client application logic often has nothing to do if there is a rate limit other than wait for it, and the sleep time ends up being arbitrary. The limits internals have a lot more information about when to most efficiently re-poll for a connection.

Expected Behavior

await strategy.wait_for_hit(limit)

aebrahim avatar Oct 16 '24 13:10 aebrahim