RetryMiddleware
in package
Middleware that retries requests based on the boolean result of invoking the provided "decider" function.
Tags
Table of Contents
Properties
- $decider : callable
- $delay : mixed
- $nextHandler : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
Methods
- __construct() : mixed
- __invoke() : PromiseInterface
- exponentialDelay() : int
- Default exponential backoff delay function.
- doRetry() : PromiseInterface
- onFulfilled() : callable
- Execute fulfilled closure
- onRejected() : callable
- Execute rejected closure
Properties
$decider
private
callable
$decider
$delay
private
mixed
$delay
Tags
$nextHandler
private
callable(RequestInterface, array<string|int, mixed>): PromiseInterface
$nextHandler
Methods
__construct()
public
__construct(callable $decider, callable(RequestInterface, array<string|int, mixed>): PromiseInterface $nextHandler[, callable(int): int|null $delay = null ]) : mixed
Parameters
- $decider : callable
-
Function that accepts the number of retries, a request, [response], and [exception] and returns true if the request is to be retried.
- $nextHandler : callable(RequestInterface, array<string|int, mixed>): PromiseInterface
-
Next handler to invoke.
- $delay : callable(int): int|null = null
-
Function that accepts the number of retries and returns the number of milliseconds to delay.
__invoke()
public
__invoke(RequestInterface $request, array<string|int, mixed> $options) : PromiseInterface
Parameters
- $request : RequestInterface
- $options : array<string|int, mixed>
Return values
PromiseInterfaceexponentialDelay()
Default exponential backoff delay function.
public
static exponentialDelay(int $retries) : int
Parameters
- $retries : int
Return values
int —milliseconds.
doRetry()
private
doRetry(RequestInterface $request, array<string|int, mixed> $options[, ResponseInterface|null $response = null ]) : PromiseInterface
Parameters
- $request : RequestInterface
- $options : array<string|int, mixed>
- $response : ResponseInterface|null = null
Return values
PromiseInterfaceonFulfilled()
Execute fulfilled closure
private
onFulfilled(RequestInterface $request, array<string|int, mixed> $options) : callable
Parameters
- $request : RequestInterface
- $options : array<string|int, mixed>
Return values
callableonRejected()
Execute rejected closure
private
onRejected(RequestInterface $req, array<string|int, mixed> $options) : callable
Parameters
- $req : RequestInterface
- $options : array<string|int, mixed>