We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5ff128a commit 0ab8f2fCopy full SHA for 0ab8f2f
1 file changed
src/CLI/Console.php
@@ -190,16 +190,24 @@ static public function isInteractive(): bool
190
/**
191
* @param callable $callback
192
* @param int $sleep in seconds
193
+ * @param callable $onError
194
*/
- static public function loop(callable $callback, $sleep = 1 /* 1 second */): void
195
+ static public function loop(callable $callback, $sleep = 1 /* 1 second */, callable $onError = null): void
196
{
197
gc_enable();
198
199
$time = 0;
200
201
while (!connection_aborted() || PHP_SAPI == "cli") {
-
202
- $callback();
+ try {
203
+ $callback();
204
+ } catch(\Exception $e) {
205
+ if($onError != null) {
206
+ $onError($e);
207
+ } else {
208
+ throw $e;
209
+ }
210
211
212
sleep($sleep);
213
0 commit comments