Skip to content

Commit f06f2f0

Browse files
committed
bug #38353 [RateLimiter] Call all compound limiters on failure and added IO blocking (wouterj)
This PR was merged into the 5.2-dev branch. Discussion ---------- [RateLimiter] Call all compound limiters on failure and added IO blocking | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Two small improvements that I missed in #38257: * Added `wait()` method, to be able to do logic like this: ```php while (!($limit = $limiter->consume())->isAccepted()) { $limit->wait(); } ``` * Fixed the `CompoundLimiter` to always call all limiters (even when one already blocks). This was the original behavior of the compound limiter and imho the best behavior (at least, it's always consistent and doesn't rely on the order of limiters - which is unsorted). Commits ------- 0279f88 Call all compound limiters on failure and added IO blocking
2 parents aa66149 + 0279f88 commit f06f2f0

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Symfony/Component/RateLimiter/CompoundLimiter.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public function consume(int $tokens = 1): Limit
3737
foreach ($this->limiters as $limiter) {
3838
$limit = $limiter->consume($tokens);
3939

40-
if (0 === $limit->getRemainingTokens()) {
41-
return $limit;
42-
}
43-
4440
if (null === $minimalLimit || $limit->getRemainingTokens() < $minimalLimit->getRemainingTokens()) {
4541
$minimalLimit = $limit;
4642
}

src/Symfony/Component/RateLimiter/Limit.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ public function getRemainingTokens(): int
4343
{
4444
return $this->availableTokens;
4545
}
46+
47+
public function wait(): void
48+
{
49+
sleep(($this->retryAfter->getTimestamp() - time()) * 1e6);
50+
}
4651
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy