pferd/PFERD/limiter.py

14 lines
330 B
Python
Raw Normal View History

2021-04-29 10:24:28 +02:00
import asyncio
from contextlib import asynccontextmanager
from typing import AsyncIterator
2021-04-29 10:24:28 +02:00
class Limiter:
def __init__(self, limit: int = 10):
self._semaphore = asyncio.Semaphore(limit)
@asynccontextmanager
async def limit(self) -> AsyncIterator[None]:
2021-04-29 16:37:42 +02:00
async with self._semaphore:
2021-04-29 10:24:28 +02:00
yield