Skip to content

Instantly share code, notes, and snippets.

@DannyMor
Last active April 20, 2020 15:37
Show Gist options
  • Save DannyMor/01c9830a495b690dad83827208bfd81f to your computer and use it in GitHub Desktop.
Save DannyMor/01c9830a495b690dad83827208bfd81f to your computer and use it in GitHub Desktop.
class RateLimiter:
def __init__(self, rate_limit: int, concurrency_limit: int) -> None:
self.rate_limit = rate_limit
self.tokens_queue = asyncio.Queue(rate_limit)
self.tokens_consumer_task = asyncio.create_task(self.consume_tokens())
self.semaphore = asyncio.Semaphore(concurrency_limit)
async def add_token(self) -> None:
pass
async def consume_tokens(self) -> None:
pass
async def throttle(self) -> None:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment