Add docstrings to AsyncRateLimiter

This commit is contained in:
Kristóf Tóth 2018-07-31 09:19:42 +02:00
parent 128f48702a
commit 3c3012ffe8

View File

@ -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