From 3c3012ffe80c0c13f60bb92097e04839196aaf03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 31 Jul 2018 09:19:42 +0200 Subject: [PATCH] Add docstrings to AsyncRateLimiter --- lib/tfw/decorators/rate_limiter.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/tfw/decorators/rate_limiter.py b/lib/tfw/decorators/rate_limiter.py index 371e732..134dd3e 100644 --- a/lib/tfw/decorators/rate_limiter.py +++ b/lib/tfw/decorators/rate_limiter.py @@ -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