consume() публичный Метод

This method consumes only tokens if there are sufficient tokens available. If there aren't sufficient tokens, no tokens will be removed and the remaining seconds to wait are written to $seconds. This method is threadsafe.
public consume ( integer $tokens, &$seconds ) : boolean
$tokens integer The token amount.
Результат boolean If tokens were consumed.
Пример #1
0
 /**
  * Test the capacity limit of the bucket
  *
  * @test
  */
 public function testCapacity()
 {
     $rate = new Rate(1, Rate::SECOND);
     $tokenBucket = new TokenBucket(10, $rate, new SingleProcessStorage());
     $tokenBucket->bootstrap();
     sleep(11);
     $this->assertTrue($tokenBucket->consume(10));
     $this->assertFalse($tokenBucket->consume(1));
 }
 /**
  * After consuming too many, getTokens() should return the same as before.
  *
  * @test
  */
 public function getTokensShouldReturnSameAfterConsumingTooMany()
 {
     $rate = new Rate(1, Rate::SECOND);
     $bucket = new TokenBucket(10, $rate, new SingleProcessStorage());
     $bucket->bootstrap(10);
     try {
         $bucket->consume(11);
         $this->fail("Expected an exception.");
     } catch (\LengthException $e) {
         // expected
     }
     $this->assertEquals(10, $bucket->getTokens());
 }