Retry
class Retry
Helper class that allows you to retry a callable a set number of times if it fails.
Properties
protected callable | $callable | The callable. | |
protected int | $attempts | The number of attempts. | |
protected int | $wait | The time we want to want to wait between each attempt in microseconds. | |
protected bool | $exponentialWait | Should the time between each attempt increase exponentially? | |
protected callable|null | $decider | Callable that decides whether or not we should retry. |
Methods
Constructor.
Sets the number of attempts.
Sets the time we want to want to wait between each attempt in microseconds.
Enables exponential waiting.
Sets the decider that decides whether or not we should retry.
Returns the number of microseconds we should wait for.
Executes and returns the return value of the callable.
Executes and returns the return value of the callable.
Details
at line 63
__construct(callable $callable, int $attempts = 5, int $wait = 50000, bool $exponentialWait = false, callable|null $decider = null)
Constructor.
at line 82
Retry
setAttempts(int $attempts)
Sets the number of attempts.
at line 95
Retry
setWait(int $wait)
Sets the time we want to want to wait between each attempt in microseconds.
at line 107
Retry
exponentialWait()
Enables exponential waiting.
at line 120
Retry
setDecider(callable $decider)
Sets the decider that decides whether or not we should retry.
at line 133
protected int
calculateWait(int $attempts)
Returns the number of microseconds we should wait for.
at line 148
mixed
execute()
Executes and returns the return value of the callable.
at line 176
mixed
__invoke()
Executes and returns the return value of the callable.