From 5dcdd8395944a7e22c6815cd2d99f99681da69f9 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Mon, 20 May 2019 14:10:59 -0500 Subject: [PATCH] Declare variables as static within function --- lib/Coroutine.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Coroutine.php b/lib/Coroutine.php index 071622e..c987b02 100644 --- a/lib/Coroutine.php +++ b/lib/Coroutine.php @@ -72,20 +72,20 @@ final class Coroutine implements Promise return; } - /** @var bool Used to control iterative coroutine continuation. */ - $immediate = true; - - /** @var \Throwable|null Promise failure reason when executing next coroutine step, null at all other times. */ - $exception = null; - - /** @var mixed Promise success value when executing next coroutine step, null at all other times. */ - $value = null; - /** * @param \Throwable|null $e Exception to be thrown into the generator. * @param mixed $v Value to be sent into the generator. */ - $onResolve = function ($e, $v) use ($generator, &$exception, &$value, &$immediate, &$onResolve) { + $onResolve = function ($e, $v) use ($generator, &$onResolve) { + /** @var bool Used to control iterative coroutine continuation. */ + static $immediate = true; + + /** @var \Throwable|null Promise failure reason when executing next coroutine step, null at all other times. */ + static $exception; + + /** @var mixed Promise success value when executing next coroutine step, null at all other times. */ + static $value; + $exception = $e; $value = $v; @@ -137,7 +137,7 @@ final class Coroutine implements Promise try { $yielded->onResolve($onResolve); - unset($generator, $yielded, $exception, $value, $immediate, $onResolve); + unset($generator, $yielded, $onResolve); } catch (\Throwable $e) { Loop::defer(static function () use ($e) { throw $e;