Skip to content

Commit

Permalink
Now hooks accepts catched exception as argument
Browse files Browse the repository at this point in the history
  • Loading branch information
acelot committed Jan 25, 2019
1 parent 4a27cd3 commit bf34ab1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Retry.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function __construct(callable $callable, int $timeout = -1, int $count =
*/
public function run()
{
$count = $this->count;
$count = 0;
$start = microtime(true);

while (true) {
Expand All @@ -89,20 +89,20 @@ public function run()
}

// Check count
if ($this->count > -1 && --$count <= 0) {
if ($this->count > -1 && ++$count >= $this->count) {
throw $e;
}

// Before pause hook
if (array_key_exists(self::BEFORE_PAUSE_HOOK, $this->hooks)) {
call_user_func($this->hooks[self::BEFORE_PAUSE_HOOK]);
call_user_func($this->hooks[self::BEFORE_PAUSE_HOOK], $e);
}

usleep($this->pause);

// After pause hook
if (array_key_exists(self::AFTER_PAUSE_HOOK, $this->hooks)) {
call_user_func($this->hooks[self::AFTER_PAUSE_HOOK]);
call_user_func($this->hooks[self::AFTER_PAUSE_HOOK], $e);
}
}
}
Expand Down

0 comments on commit bf34ab1

Please sign in to comment.