1
0
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:
Aaron Piotrowski 2020-02-28 13:35:37 -06:00 committed by GitHub
parent 2ac3b550c4
commit 34bcf727dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}