Open iainelder opened 4 months ago
The Check without consuming example gave me a clue.
I need to add this pattern into any function that I want to be rate-limited.
while not moving_window.test(one_per_minute, "test_namespace"):
time.sleep(0.01)
assert moving_window.hit(one_per_minute, "test_namespace")
Is that how you expect me to use this? If so, I would make a PR that clarifies this in the docs.
Better still would be a decorator (or indications on how to build one) so I don't have to add this inside my functions.
Came here from Justin Van Winkle's survey of Python rate limiters. He said limits "seems to work", which is high praise because the rest were somehow broken.
Am I missing something with the
hit
function?Quickstart shows how to assert whether it returns
True
orFalse
and to sleep to make a previousFalse
turnTrue
.I want a rate limiter that blocks until the request would satisfy the limit; that is, as soon as
hit
would returnTrue
.I suppose I could built something like that using
hit
, but I don't want to. If I have to start writing sleeps into my code, then I think there's something missing from my rate limiter library.