From 34bcf727dcc8d99184d1dc32c16d1f220288b119 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Fri, 28 Feb 2020 13:35:37 -0600 Subject: [PATCH] Add parameter for custom timeout message (#299) --- lib/TimeoutCancellationToken.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/TimeoutCancellationToken.php b/lib/TimeoutCancellationToken.php index e4c9cd1..f2617e7 100644 --- a/lib/TimeoutCancellationToken.php +++ b/lib/TimeoutCancellationToken.php @@ -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); }