Skip to content

Commit

Permalink
feat(#16): use as standard wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Oct 25, 2016
1 parent 641e0c4 commit 3839329
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions paco/throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ def throttle(coro, limit=1, timeframe=1,
Usage::
# Use as simple wrapper
task = paco.throttle(coro, limit=1, timeframe=1)
task(1)
task(1) # ignored!
await task(1)
await task(2) # ignored!
time.sleep(1)
task(1) # executed!
await task(3) # executed!
# Use as decorator
@paco.throttle(limit=1, timeframe=1)
async def task(num):
return num * 2
await task(1) # => 2
await task(2) # => 2 (ignored)
time.sleep(1)
await task(3) # => 6
"""
assert_corofunction(coro=coro)

Expand Down

0 comments on commit 3839329

Please sign in to comment.