mirror of
https://github.com/Garmelon/PFERD.git
synced 2026-04-12 07:25:04 +02:00
16 lines
402 B
Python
16 lines
402 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]:
|
|
await self._semaphore.acquire()
|
|
try:
|
|
yield
|
|
finally:
|
|
self._semaphore.release()
|