Core/src/RequestWrapper.php
public function sendAsync(RequestInterface $request, array $options = [])
    {
        // Unfortunately, the current ExponentialBackoff implementation doesn't
        // play nicely with promises.
        $retryAttempt = 0;
        $fn = function ($retryAttempt) use (&$fn, $request, $options) {
            $asyncHttpHandler = $this->asyncHttpHandler;
            $retryOptions = $this->getRetryOptions($options);
            if (!$retryOptions['calcDelayFunction']) {
                $retryOptions['calcDelayFunction'] = [ExponentialBackoff::class, 'calculateDelay'];
            }

            return $asyncHttpHandler(
                $this->applyHeaders($request),
                $this->getRequestOptions($options)
            )->then(null, function (\Exception $ex) use ($fn, $retryAttempt, $retryOptions) {
                $shouldRetry = $retryOptions['retryFunction']($ex);

                if ($shouldRetry === false || $retryAttempt >= $retryOptions['retries']) {
                    throw $this->convertToGoogleException($ex);
                }

                $delay = $retryOptions['calcDelayFunction']($retryAttempt);
                $retryOptions['delayFunction']($delay);
                $retryAttempt++;

                return $fn($retryAttempt);
            });
        };

        return $fn($retryAttempt);
    }
public function sendAsync(RequestInterface $request, array $options = [])
    {
        // Unfortunately, the current ExponentialBackoff implementation doesn't
        // play nicely with promises.
        $retryAttempt = 0;
        $fn = function ($retryAttempt) use (&$fn, $request, $options) {
            $asyncHttpHandler = $this->asyncHttpHandler;
            $retryOptions = $this->getRetryOptions($options);
            if (!$retryOptions['calcDelayFunction']) {
                $retryOptions['calcDelayFunction'] = [ExponentialBackoff::class, 'calculateDelay'];
            }

            return $asyncHttpHandler(
                $this->applyHeaders($request),
                $this->getRequestOptions($options)
            )->then(null, function (\Exception $ex) use ($fn, $retryAttempt, $retryOptions) {
                $shouldRetry = $retryOptions['retryFunction']($ex);

                if ($shouldRetry === false || $retryAttempt >= $retryOptions['retries']) {
                    throw $this->convertToGoogleException($ex);
                }

                $delay = $retryOptions['calcDelayFunction']($retryAttempt);
                $retryOptions['delayFunction']($delay);
                $retryAttempt++;

                return $fn($retryAttempt);
            });
        };

        return $fn($retryAttempt);
    }
public function sendAsync ( RequestInterface $ request , array $ options = [ ] ) { // Unfortunately, the current ExponentialBackoff implementation doesn't // play nicely with promises. $ retryAttempt = 0 ; $ fn = function ( $ retryAttempt ) use ( & $ fn , $ request , $ options ) { $ asyncHttpHandler = $ this -> asyncHttpHandler ; $ retryOptions = $ this -> getRetryOptions ( $ options ) ; if ( ! $ retryOptions [ 'calcDelayFunction' ] ) { $ retryOptions [ 'calcDelayFunction' ] = [ ExponentialBackoff :: class , 'calculateDelay' ] ; } return $ asyncHttpHandler ( $ this -> applyHeaders ( $ request ) , $ this -> getRequestOptions ( $ options ) ) -> then ( null , function ( \ Exception $ ex ) use ( $ fn , $ retryAttempt , $ retryOptions ) { $ shouldRetry = $ retryOptions [ 'retryFunction' ] ( $ ex ) ; if ( $ shouldRetry === false || $ retryAttempt >= $ retryOptions [ 'retries' ] ) { throw $ this -> convertToGoogleException ( $ ex ) ; } $ delay = $ retryOptions [ 'calcDelayFunction' ] ( $ retryAttempt ) ; $ retryOptions [ 'delayFunction' ] ( $ delay ) ; $ retryAttempt ++ ; return $ fn ( $ retryAttempt ) ; } ) ; } ; return $ fn ( $ retryAttempt ) ; }
Deliver the request asynchronously.

@param RequestInterface $request A PSR-7 request.
@param array $options [optional] {
Request options.

@type float $requestTimeout Seconds to wait before timing out the
request. **Defaults to** `0`.
@type int $retries Number of retries for a failed request.
**Defaults to** `3`.
@type callable $restRetryFunction Sets the conditions for whether or
not a request should attempt to retry. Function signature should
match: `function (\Exception $ex) : bool`.
@type callable $restDelayFunction Executes a delay, defaults to
utilizing `usleep`. Function signature should match:
`function (int $delay) : void`.
@type callable $restCalcDelayFunction Sets the conditions for
determining how long to wait between attempts to retry. Function
signature should match: `function (int $attempt) : int`.
@type array $restOptions HTTP client specific configuration options.
}
@return PromiseInterface<ResponseInterface>
@experimental The experimental flag means that while we believe this method
or class is ready for use, it may change before release in backwards-
incompatible ways. Please use with caution, and test thoroughly when
upgrading.
Deliver the request asynchronously .