mirror of
https://github.com/danog/amp.git
synced 2024-12-12 09:29:45 +01:00
Add parameter for custom timeout message (#299)
This commit is contained in:
parent
2ac3b550c4
commit
34bcf727dc
@ -15,14 +15,15 @@ final class TimeoutCancellationToken implements CancellationToken
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $timeout Milliseconds until cancellation is requested.
|
* @param int $timeout Milliseconds until cancellation is requested.
|
||||||
|
* @param string $message Message for TimeoutException. Default is "Operation timed out".
|
||||||
*/
|
*/
|
||||||
public function __construct(int $timeout)
|
public function __construct(int $timeout, string $message = "Operation timed out")
|
||||||
{
|
{
|
||||||
$source = new CancellationTokenSource;
|
$source = new CancellationTokenSource;
|
||||||
$this->token = $source->getToken();
|
$this->token = $source->getToken();
|
||||||
|
|
||||||
$this->watcher = Loop::delay($timeout, static function () use ($source) {
|
$this->watcher = Loop::delay($timeout, static function () use ($source, $message) {
|
||||||
$source->cancel(new TimeoutException);
|
$source->cancel(new TimeoutException($message));
|
||||||
});
|
});
|
||||||
Loop::unreference($this->watcher);
|
Loop::unreference($this->watcher);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user