pferd/PFERD/limiter.py
2021-04-29 20:20:25 +02:00

14 lines
330 B
Python

import asyncio
from contextlib import asynccontextmanager
from typing import AsyncIterator
class Limiter:
def __init__(self, limit: int = 10):
self._semaphore = asyncio.Semaphore(limit)
@asynccontextmanager
async def limit(self) -> AsyncIterator[None]:
async with self._semaphore:
yield