mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 12:31:21 +00:00
Add docstrings to AsyncRateLimiter
This commit is contained in:
parent
128f48702a
commit
3c3012ffe8
@ -7,10 +7,9 @@ from time import time, sleep
|
||||
from tfw.decorators.lazy_property import lazy_property
|
||||
|
||||
|
||||
# TODO: add this to sphinx docs
|
||||
class RateLimiter:
|
||||
"""
|
||||
Decorator class for rate limiting.
|
||||
Decorator class for rate limiting, blocking.
|
||||
|
||||
When applied to a function this decorator will apply rate limiting
|
||||
if the function is invoked more frequently than rate_per_seconds.
|
||||
@ -59,9 +58,22 @@ class RateLimiter:
|
||||
return 0
|
||||
|
||||
|
||||
# TODO document this
|
||||
class AsyncRateLimiter(RateLimiter):
|
||||
"""
|
||||
Decorator class for rate limiting, non-blocking.
|
||||
|
||||
The semantics of the rate limiting are similar to that of RateLimiter,
|
||||
but this decorator never blocks, instead it adds an async callback version
|
||||
of the decorated function to the IOLoop to be executed after the rate limiting
|
||||
has expired.
|
||||
"""
|
||||
def __init__(self, rate_per_second, ioloop_factory):
|
||||
"""
|
||||
:param rate_per_second: max frequency the decorated method should be
|
||||
invoked with
|
||||
:param ioloop_factory: callable that should return an instance of the
|
||||
IOLoop of the application
|
||||
"""
|
||||
self._ioloop_factory = ioloop_factory
|
||||
self._ioloop = None
|
||||
self._last_callback = None
|
||||
|
Loading…
Reference in New Issue
Block a user