diff --git a/src/functions.php b/src/functions.php index 38857fd..e593a36 100644 --- a/src/functions.php +++ b/src/functions.php @@ -22,10 +22,19 @@ function async(\Closure $closure, mixed ...$args): Future static $run = null; $run ??= static function (FutureState $state, \Closure $closure, array $args): void { + $s = $state; + $state = null; + + $c = $closure; + $closure = null; + + $a = $args; + $args = null; + try { - $state->complete($closure(...$args)); + $s->complete($c(...$a)); } catch (\Throwable $exception) { - $state->error($exception); + $s->error($exception); } };