You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now the only way to get a RateLimit instance is to actually consume a token. I have so far not seen a way to get the RateLimit without that. Trying to retrieve the RateLimit without consuming a token by using 0 as parameter to RateLimiterInterface::consume() didn't work out the way I expected as - at least in the SLidingWindowLimiter the RateLimit::isAccepted() will always return true - even when there is no token available any more.
This behaviour makes sense as I am not consuming a token.
Having a way to get a RateLimit that has the isAccepted method return true or false depending on the currently available tokens would be helpful for applications that consume a token under certain circumstances along the code-path but that want to immediately at the beginning stop processing when no token is available any more. That way the application can save a lot of processing time before coming to the conclusion that the limit has been reached.
Example
publicfunctionmyAction(): Request
{
// This is what we currently try which does not work//$limit = $this->rateLimiter->consume(0)$limit = $this->rateLimiter->getCurrentLimit();
if (! $limit->isAccepted()) {
thrownewTooManyRequestsHttpException($limit->getRetryAfter()->getTimestamp());
}
// ... do some heavy computing stuff hereif (/* add some condition here */true) {
// We only want to consume a token under certain circumstances$this->rateLimiter->consume(1);
}
}
Example implementation for the sliding window ratelimiter:
Description
Right now the only way to get a
RateLimit
instance is to actually consume a token. I have so far not seen a way to get theRateLimit
without that. Trying to retrieve theRateLimit
without consuming a token by using0
as parameter toRateLimiterInterface::consume()
didn't work out the way I expected as - at least in theSLidingWindowLimiter
theRateLimit::isAccepted()
will always return true - even when there is no token available any more.This behaviour makes sense as I am not consuming a token.
Having a way to get a
RateLimit
that has theisAccepted
method returntrue
orfalse
depending on the currently available tokens would be helpful for applications that consume a token under certain circumstances along the code-path but that want to immediately at the beginning stop processing when no token is available any more. That way the application can save a lot of processing time before coming to the conclusion that the limit has been reached.Example
Example implementation for the sliding window ratelimiter:
The text was updated successfully, but these errors were encountered: