public function bootstrap($tokens = 0)
    {
        try {
            if ($tokens > $this->capacity) {
                throw new \LengthException(
                    "Initial token amount ($tokens) is larger than the capacity ($this->capacity)."
                );
            }
            if ($tokens < 0) {
                throw new \InvalidArgumentException(
                    "Initial token amount ($tokens) should be greater than 0."
                );
            }
            
            $this->storage->getMutex()
                ->check(function () {
                    return !$this->storage->isBootstrapped();
                })
                ->then(function () use ($tokens) {
                    $this->storage->bootstrap($this->tokenConverter->convertTokensToMicrotime($tokens));
                });
        } catch (MutexException $e) {
            throw new StorageException("Could not lock bootstrapping", 0, $e);
        }
    }
public function bootstrap($tokens = 0)
    {
        try {
            if ($tokens > $this->capacity) {
                throw new \LengthException(
                    "Initial token amount ($tokens) is larger than the capacity ($this->capacity)."
                );
            }
            if ($tokens < 0) {
                throw new \InvalidArgumentException(
                    "Initial token amount ($tokens) should be greater than 0."
                );
            }
            
            $this->storage->getMutex()
                ->check(function () {
                    return !$this->storage->isBootstrapped();
                })
                ->then(function () use ($tokens) {
                    $this->storage->bootstrap($this->tokenConverter->convertTokensToMicrotime($tokens));
                });
        } catch (MutexException $e) {
            throw new StorageException("Could not lock bootstrapping", 0, $e);
        }
    }
public function bootstrap ( $ tokens = 0 ) { try { if ( $ tokens > $ this -> capacity ) { throw new \ LengthException ( "Initial token amount ($tokens) is larger than the capacity ($this->capacity)." ) ; } if ( $ tokens < 0 ) { throw new \ InvalidArgumentException ( "Initial token amount ($tokens) should be greater than 0." ) ; } $ this -> storage -> getMutex ( ) -> check ( function ( ) { return ! $ this -> storage -> isBootstrapped ( ) ; } ) -> then ( function ( ) use ( $ tokens ) { $ this -> storage -> bootstrap ( $ this -> tokenConverter -> convertTokensToMicrotime ( $ tokens ) ) ; } ) ; } catch ( MutexException $ e ) { throw new StorageException ( "Could not lock bootstrapping" , 0 , $ e ) ; } }
Bootstraps the storage with an initial amount of tokens.

If the storage was already bootstrapped this method returns silently.

While you could call bootstrap() on each request, you should not do that!
This method will do unnecessary storage communications just to see that
bootstrapping was performed already. You therefore should call that
method in your application's bootstrap or deploy process.

This method is threadsafe.

@param int $tokens Initial amount of tokens, default is 0.

@throws StorageException Bootstrapping failed.
@throws \LengthException The initial amount of tokens is larger than the capacity.
Bootstraps the storage with an initial amount of tokens .