diff --git a/.travis.yml b/.travis.yml index ee1fba6..3ba22f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: -- 7.4 - 8.0 - nightly diff --git a/src/CLI/Console.php b/src/CLI/Console.php index 2fb28ed..f3cb3c6 100644 --- a/src/CLI/Console.php +++ b/src/CLI/Console.php @@ -190,16 +190,24 @@ static public function isInteractive(): bool /** * @param callable $callback * @param int $sleep in seconds + * @param callable $onError */ - static public function loop(callable $callback, $sleep = 1 /* 1 second */): void + static public function loop(callable $callback, $sleep = 1 /* 1 second */, callable $onError = null): void { gc_enable(); $time = 0; while (!connection_aborted() || PHP_SAPI == "cli") { - - $callback(); + try { + $callback(); + } catch(\Exception $e) { + if($onError != null) { + $onError($e); + } else { + throw $e; + } + } sleep($sleep);