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

__construct(callable $callable, int $attempts = 5, int $wait = 50000, bool $exponentialWait = false, callable|null $decider = null)

Constructor.

setAttempts(int $attempts)

Sets the number of attempts.

setWait(int $wait)

Sets the time we want to want to wait between each attempt in microseconds.

exponentialWait()

Enables exponential waiting.

setDecider(callable $decider)

Sets the decider that decides whether or not we should retry.

int
calculateWait(int $attempts)

Returns the number of microseconds we should wait for.

mixed
execute()

Executes and returns the return value of the callable.

mixed
__invoke()

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.

Parameters

callable $callable The callable
int $attempts The number of attempts
int $wait The time we want to want to wait between each attempt in microseconds
bool $exponentialWait Should the time between each attempt increase exponentially?
callable|null $decider Callable that decides whether or not we should retry

at line 82
Retry setAttempts(int $attempts)

Sets the number of attempts.

Parameters

int $attempts The maximum number of attempts

Return Value

Retry

at line 95
Retry setWait(int $wait)

Sets the time we want to want to wait between each attempt in microseconds.

Parameters

int $wait The time we want to want to wait between each attempt in microseconds

Return Value

Retry

at line 107
Retry exponentialWait()

Enables exponential waiting.

Return Value

Retry

at line 120
Retry setDecider(callable $decider)

Sets the decider that decides whether or not we should retry.

Parameters

callable $decider Callable that decides whether or not we should retry

Return Value

Retry

at line 133
protected int calculateWait(int $attempts)

Returns the number of microseconds we should wait for.

Parameters

int $attempts Number of attempts

Return Value

int

at line 148
mixed execute()

Executes and returns the return value of the callable.

Return Value

mixed

at line 176
mixed __invoke()

Executes and returns the return value of the callable.

Return Value

mixed