Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Add wait option.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuya-takeyama committed Mar 17, 2012
1 parent a603511 commit c0a072c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/RetryHandler/Proc.php
Expand Up @@ -5,6 +5,10 @@

class Proc
{
const DEFAULT_MAX_RETRY = 3;
const DEFAULT_WAIT_TIME = 1;
const DEFAULT_ACCEPTED_EXCEPTION = 'RetryHandler\RetryException';

/**
* @var callable
*/
Expand All @@ -22,7 +26,23 @@ public function __construct($proc)
$this->_proc = $proc;
}

public function retry($max)
public function retry($options, $moreOptions = array())
{
if (is_int($options)) {
$options = array('max' => $options);
}
$options = array_merge($options, $moreOptions);

$max = isset($options['max']) ? $options['max'] : self::DEFAULT_MAX_RETRY;
$wait = isset($options['wait']) ? $options['wait'] : self::DEFAULT_WAIT_TIME;
$exception = isset($options['accepted_exception']) ?
$options['accepted_exception'] :
self::DEFAULT_ACCEPTED_EXCEPTION;

return $this->_retry($max, $wait, $exception);
}

protected function _retry($max, $wait, $acceptedException)
{
for ($i = 0; $i < $max; $i++) {
try {
Expand Down

0 comments on commit c0a072c

Please sign in to comment.