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