public function exponential(int $attempt) : float
    {
        if (!is_int($attempt)) {
            throw new InvalidArgumentException('Attempt must be an integer');
        }

        if ($attempt < 1) {
            throw new InvalidArgumentException('Attempt must be >= 1');
        }

        if ($this->maxAttempsExceeded($attempt)) {
            throw new BackoffException(
                sprintf(
                    "The number of max attempts (%s) was exceeded",
                    $this->options['maxAttempts']
                )
            );
        }

        $wait = (1 << ($attempt - 1)) * 1000;

        return ($this->options['cap'] < $wait) ? $this->options['cap'] : $wait;
    }
public function exponential(int $attempt) : float
    {
        if (!is_int($attempt)) {
            throw new InvalidArgumentException('Attempt must be an integer');
        }

        if ($attempt < 1) {
            throw new InvalidArgumentException('Attempt must be >= 1');
        }

        if ($this->maxAttempsExceeded($attempt)) {
            throw new BackoffException(
                sprintf(
                    "The number of max attempts (%s) was exceeded",
                    $this->options['maxAttempts']
                )
            );
        }

        $wait = (1 << ($attempt - 1)) * 1000;

        return ($this->options['cap'] < $wait) ? $this->options['cap'] : $wait;
    }
public function exponential ( int $ attempt ) : float { if ( ! is_int ( $ attempt ) ) { throw new InvalidArgumentException ( 'Attempt must be an integer' ) ; } if ( $ attempt < 1 ) { throw new InvalidArgumentException ( 'Attempt must be >= 1' ) ; } if ( $ this -> maxAttempsExceeded ( $ attempt ) ) { throw new BackoffException ( sprintf ( "The number of max attempts (%s) was exceeded" , $ this -> options [ 'maxAttempts' ] ) ) ; } $ wait = ( 1 << ( $ attempt - 1 ) ) * 1000 ; return ( $ this -> options [ 'cap' ] < $ wait ) ? $ this -> options [ 'cap' ] : $ wait ; }
Exponential backoff algorithm.

c = attempt

E(c) = (2**c - 1)

@param int $attempt Attempt number.

@return float Time to sleep in microseconds before a new retry. The value
is in microseconds to use with usleep, sleep function only
works with seconds

@throws \InvalidArgumentException.
Exponential backoff algorithm .