|
1 | 1 | <?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
2 | 4 | namespace ScriptFUSION\Retry; |
3 | 5 |
|
4 | 6 | use Amp\Coroutine; |
|
12 | 14 | * |
13 | 15 | * @param int $tries Number of times. |
14 | 16 | * @param callable $operation Operation. |
15 | | - * @param callable $onError Optional. Exception handler. |
| 17 | + * @param callable|null $onError Optional. Exception handler. |
16 | 18 | * |
17 | 19 | * @return mixed Result of running the operation if tries is greater than zero, otherwise null. |
18 | 20 | * |
19 | | - * @throws FailingTooHardException The maximum number of attempts was reached. |
20 | | - * @throws \UnexpectedValueException The operation returned an unsupported type. |
21 | 21 | */ |
22 | | -function retry($tries, callable $operation, callable $onError = null) |
| 22 | +function retry(int $tries, callable $operation, callable $onError = null) |
23 | 23 | { |
24 | | - /** @var \Generator $generator */ |
25 | 24 | $generator = (static function () use ($tries, $operation, $onError): \Generator { |
26 | 25 | // Nothing to do if tries less than or equal to zero. |
27 | | - if (($tries |= 0) <= $attempts = 0) { |
| 26 | + if ($tries <= $attempts = 0) { |
28 | 27 | return; |
29 | 28 | } |
30 | 29 |
|
@@ -76,15 +75,13 @@ function retry($tries, callable $operation, callable $onError = null) |
76 | 75 | * |
77 | 76 | * @param int $tries Number of times. |
78 | 77 | * @param callable $operation Operation. |
79 | | - * @param callable $onError Optional. Exception handler. |
| 78 | + * @param callable|null $onError Optional. Exception handler. |
80 | 79 | * |
81 | 80 | * @return Promise Promise that returns the result of running the operation if tries is greater than zero, otherwise |
82 | 81 | * a promise that yields null. |
83 | 82 | * |
84 | | - * @throws FailingTooHardException The maximum number of attempts was reached. |
85 | | - * @throws \UnexpectedValueException The operation returned an unsupported type. |
86 | 83 | */ |
87 | | -function retryAsync($tries, callable $operation, callable $onError = null): Promise |
| 84 | +function retryAsync(int $tries, callable $operation, callable $onError = null): Promise |
88 | 85 | { |
89 | 86 | $generator = retry($tries, $operation, $onError); |
90 | 87 |
|
|
0 commit comments