Skip to content

Commit

Permalink
Merge pull request #48 from Tolerance/feature/exposes-next-wait-time-…
Browse files Browse the repository at this point in the history
…on-exponential-back-off

Exposes the next amount of time that will be waited
  • Loading branch information
sroze committed May 10, 2016
2 parents e69de26 + cf8ef45 commit df4dfc1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Tolerance/Waiter/ExponentialBackOff.php
Expand Up @@ -38,8 +38,23 @@ public function __construct(Waiter $waiter, $exponent)
*/
public function wait($seconds = 0)
{
$time = $seconds + exp($this->exponent++);
$time = $this->getNextTime($seconds);

$this->waiter->wait($time);

$this->exponent++;
}

/**
* Return the amount of time that will be waited the next `wait` call.
*
* @param int $seconds
*
* @return int
*/
public function getNextTime($seconds = 0)
{
return $seconds + exp($this->exponent);
}
}

0 comments on commit df4dfc1

Please sign in to comment.