Skip to content

Commit

Permalink
setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrguric committed Nov 24, 2023
1 parent 0898dc4 commit 60146a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ If you wish to define custom behaviour when request is rate-limited you can via
$account_tx->setCooldownSeconds(10);
//(optional) Override default number of tries when request is rate-limited (default is 3)
$account_tx->setTries(5);
//(optional) Set http timeout to 3 seconds (default is 0 - eg no timeout)
// After 3 seconds method will throw \XRPLWin\XRPL\Exceptions\BadRequestException on timeout
$account_tx->setTimeout(3);

//(optional) Define custom cooldown callback
$account_tx->setCooldownHandler(
Expand Down
16 changes: 16 additions & 0 deletions src/Api/AbstractMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ abstract class AbstractMethod
protected ?Closure $cooldown_callback = null;
protected int $tries = 3; //how much times request is retried if rate limiting is reached
protected int $tries_tracker = 0; //how much tries are executed so far
protected int $timeout = 0; //http timeout, 0 is no timeout - see guzzle docs

protected ?Throwable $lastException;

Expand Down Expand Up @@ -106,6 +107,7 @@ public function requestAsync(): PromiseInterface
->requestAsync('POST', $this->endpoint, [
'http_errors' => true,
'connect_timeout' => 10,
'timeout' => $this->timeout,
'body' => \json_encode($p),
'headers' => $this->client->getHeaders()
]);
Expand Down Expand Up @@ -168,6 +170,7 @@ protected function sendOnce(bool $silent = false)
->request('POST', $this->endpoint, [
'http_errors' => false,
'connect_timeout' => 10,
'timeout' => $this->timeout,
'body' => \json_encode($p),
'headers' => $this->client->getHeaders()
]);
Expand Down Expand Up @@ -389,6 +392,7 @@ protected function cooldown(int $current_try = 1): void
/**
* Sets how much times script will try to re-query Ledger in case of Rate limited response.
* Default value is 5 seconds.
* @param int $tries
* @return self
*/
public function setTries(int $tries): self
Expand All @@ -399,4 +403,16 @@ public function setTries(int $tries): self
$this->tries = $tries;
return $this;
}

/**
* Set timeout value of http request, this value will be sent to guzzle http client.
* Default value is 0
* @param int $seconds
* @return self
*/
public function setTimeout(int $seconds): self
{
$this->timeout = $seconds;
return $this;
}
}

0 comments on commit 60146a7

Please sign in to comment.