/** * {@inheritdoc} */ public function wait($identifier = '') { if ($this->rateLimit->hasReachedLimit($identifier)) { $this->waiter->wait($this->rateLimit->getTicksBeforeUnderLimit($identifier)); } $this->rateLimit->tick($identifier); }
function it_waits_if_the_limit_is_reached(RateLimit $rateLimit, Waiter $waiter) { $rateLimit->hasReachedLimit('id')->willReturn(true); $rateLimit->getTicksBeforeUnderLimit('id')->willReturn(1.234); $waiter->wait(1.234)->shouldBeCalled(); $rateLimit->tick('id')->shouldBeCalled(); $this->wait('id'); }
function it_waits_the_number_of_required_tick_if_the_rate_limit_is_reached(OperationRunner $runner, RateLimit $rateLimit, Waiter $waiter, Operation $operation) { $rateLimit->hasReachedLimit(Argument::any())->willReturn(true); $rateLimit->getTicksBeforeUnderLimit(Argument::any())->willReturn(10); $waiter->wait(10)->shouldBeCalled(); $runner->run($operation)->shouldBeCalled(); $rateLimit->tick(Argument::any())->shouldBeCalled(); $this->run($operation); }
/** * {@inheritdoc} */ public function run(Operation $operation) { $identifier = $this->identifierStrategy->getOperationIdentifier($operation); if ($this->rateLimit->hasReachedLimit($identifier)) { $this->waiter->wait($this->rateLimit->getTicksBeforeUnderLimit($identifier)); } $this->rateLimit->tick($identifier); return $this->runner->run($operation); }