mirror of
https://github.com/danog/amp.git
synced 2024-12-02 17:37:50 +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 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;
|
||||
$this->token = $source->getToken();
|
||||
|
||||
$this->watcher = Loop::delay($timeout, static function () use ($source) {
|
||||
$source->cancel(new TimeoutException);
|
||||
$this->watcher = Loop::delay($timeout, static function () use ($source, $message) {
|
||||
$source->cancel(new TimeoutException($message));
|
||||
});
|
||||
Loop::unreference($this->watcher);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user