You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
677 B
PHTML

<?php
namespace App\Services;
use Closure;
use function React\Async\async;
use React\EventLoop\Loop;
class AsyncService
{
public static function async(Closure $closure, $isAsync = true)
{
1 year ago
info(self::class, [$closure]);
if ($isAsync) {
Loop::addTimer(0.1, async(function () use ($closure) {
1 year ago
try {
$closure();
} catch (\Exception $e) {
info(self::class, [
'message' => $e->getMessage(),
'error' => $e,
]);
}
}));
} else {
$closure();
}
}
}