Skip to content

Commit

Permalink
update add retry logic with only logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyễn Quang Trường committed Jan 5, 2023
1 parent a0b8dec commit 6cd0a95
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Servers/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ function (
try_time: $retries + 1
);

foreach ($this->current_host->getRetriesLogic() as $retry_callable) {
if ($this->current_host->getRetryLogic() && is_callable($this->current_host->getRetryLogic())) {
$result_call_func = call_user_func(
$retry_callable,
$this->current_host->getRetryLogic(),
$this->current_host,
$retries,
$request,
Expand Down
14 changes: 7 additions & 7 deletions src/Servers/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
final class Host implements HostInterface
{
/**
* @var array $retries_logic
* @var callable $retry_logic
* */
private array $retries_logic = [];
private $retry_logic = null;

/**
* Function constructor
Expand Down Expand Up @@ -67,21 +67,21 @@ public function validateConstructor()
*/
public function addRetryLogic(callable $retry_logic): void
{
if(!is_callable($retry_logic)){
if (!is_callable($retry_logic)) {
throw new InvalidCallableException();
}

$this->retries_logic[] = $retry_logic;
$this->retry_logic = $retry_logic;
}

/**
* Get retry logic
*
* @return array
* @return callable|null
* */
public function getRetriesLogic(): array
public function getRetryLogic(): callable|null
{
return $this->retries_logic;
return $this->retry_logic;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Servers/HostInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function addRetryLogic(callable $retry_logic): void;
/**
* Get retry logic
*
* @return array
* @return callable|null
* */
public function getRetriesLogic(): array;
public function getRetryLogic(): callable|null;
}

0 comments on commit 6cd0a95

Please sign in to comment.