File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed
Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ The following back-off decorators are available:
159159- [ ExponentialBackOff] ( ../src/ExponentialBackOff.php )
160160- [ DecorrelatedBackOff] ( ../src/DecorrelatedBackOff.php )
161161- [ ImmediatelyThrowableBackOff] ( ../src/ImmediatelyThrowableBackOff.php )
162+ - [ NullBackOff] ( ../src/NullBackOff.php )
162163
163164## Retry exceptions
164165
@@ -168,6 +169,7 @@ Configure BackOff and ExceptionClassifier to retry your business logic when an e
168169<?php
169170
170171use Orangesoft\BackOff\ExponentialBackOff;
172+ use Orangesoft\BackOff\NullBackOff;
171173use Orangesoft\BackOff\Duration\Seconds;
172174use Orangesoft\BackOff\Retry\ExceptionClassifier\ExceptionClassifier;
173175use Orangesoft\BackOff\Retry\Retry;
@@ -184,6 +186,18 @@ $exceptionClassifier = new ExceptionClassifier([
184186$retry = new Retry($backOff, $exceptionClassifier);
185187```
186188
189+ If you don't need any back-off at all use NullBackOff which just count attempts:
190+
191+ ``` php
192+ $backOff = new NullBackOff(maxAttempts: 3);
193+
194+ $exceptionClassifier = new ExceptionClassifier([
195+ \RuntimeException::class,
196+ ]);
197+
198+ $retry = new Retry($backOff, $exceptionClassifier);
199+ ```
200+
187201Put the business logic in a callback function and call it:
188202
189203``` php
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Orangesoft \BackOff ;
6+
7+ final class NullBackOff implements BackOffInterface
8+ {
9+ public function __construct (
10+ private int |float $ maxAttempts = 3 ,
11+ ) {
12+ }
13+
14+ public function backOff (int $ attempt , \Throwable $ throwable ): void
15+ {
16+ if ($ attempt > $ this ->maxAttempts ) {
17+ throw $ throwable ;
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Orangesoft \BackOff \Tests ;
6+
7+ use Orangesoft \BackOff \NullBackOff ;
8+ use PHPUnit \Framework \TestCase ;
9+
10+ class NullBackOffTest extends TestCase
11+ {
12+ public function testBackOff (): void
13+ {
14+ $ nullBackOff = new NullBackOff (maxAttempts: 3 );
15+
16+ $ throwable = new \Exception ();
17+
18+ $ this ->expectExceptionObject ($ throwable );
19+
20+ $ nullBackOff ->backOff (4 , $ throwable );
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments