Skip to content

Commit 31a20c6

Browse files
committed
Introducing loop deal and accuracy.
1 parent 1541a9a commit 31a20c6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/CLI/Console.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,11 @@ public static function isInteractive(): bool
194194
}
195195

196196
/**
197-
* @param callable $callback
198-
* @param int $sleep // in seconds!
199-
* @param int $delay // in seconds!
200-
* @param callable|null $onError
197+
* @param callable $callback
198+
* @param int $sleep // in seconds!
199+
* @param int $delay // in seconds!
200+
* @param callable|null $onError
201+
*
201202
* @throws \Exception
202203
*/
203204
public static function loop(callable $callback, int $sleep = 1 /* seconds */, int $delay = 0 /* seconds */, callable $onError = null): void
@@ -206,18 +207,16 @@ public static function loop(callable $callback, int $sleep = 1 /* seconds */, in
206207

207208
$time = 0;
208209

209-
if($delay > 0){
210+
if ($delay > 0) {
210211
sleep($delay);
211212
}
212213

213214
while (! connection_aborted() || PHP_SAPI == 'cli') {
214-
215215
$suspend = $sleep;
216216

217217
try {
218218
$execStart = \time();
219219
$callback();
220-
221220
} catch (\Exception $e) {
222221
if ($onError != null) {
223222
$onError($e);
@@ -226,7 +225,7 @@ public static function loop(callable $callback, int $sleep = 1 /* seconds */, in
226225
}
227226
}
228227

229-
$execTotal = \time() - $execStart;
228+
$execTotal = \time() - $execStart;
230229
$suspend = $suspend - $execTotal;
231230

232231
$intSeconds = intval($suspend);

0 commit comments

Comments
 (0)