[docs]classRateLimiter(BucketBasedRateController):"""Rate controller that raises an error if a request cannot be fulfilled instantly."""
[docs]@asynccontextmanager@overrideasyncdefrequest(self,tokens:float=1,**_:Any)->AsyncIterator[None]:"""Context manager that acquires the given amount of tokens while holding concurrency. Args: tokens: The number of tokens to acquire. Defaults to `1`. Raises: RateLimit: The request cannot be fulfilled instantly. """self._assert_can_acquire(tokens)ifself._bucketisnotNone:self._bucket.acquire(tokens)withself._hold_concurrency():yield