From e56a64d68837305ab4ea0529b1b8fe44a643e27d Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Tue, 12 Jul 2022 00:15:19 +0200 Subject: [PATCH] Fix circular reference on exceptions Fixes #394. --- src/functions.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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); } };