From 54230ffe759f3c0e85b37084d86f9aa700f28610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 3 Apr 2023 11:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Context/CoroutineContext.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Context/CoroutineContext.php b/Context/CoroutineContext.php index 4476e44..af0e39d 100644 --- a/Context/CoroutineContext.php +++ b/Context/CoroutineContext.php @@ -32,6 +32,9 @@ class CoroutineContext implements ContextInterface public static function get(string $key, mixed $defaultValue = null, ?int $coroutineId = null): mixed { // TODO: Implement get() method. + if (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } return Coroutine::getContext($coroutineId)[$key] ?? $defaultValue; } @@ -43,6 +46,9 @@ class CoroutineContext implements ContextInterface public static function exists(string $key, ?int $coroutineId = null): bool { // TODO: Implement exists() method. + if (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } return isset(Coroutine::getContext($coroutineId)[$key]); } @@ -54,6 +60,9 @@ class CoroutineContext implements ContextInterface public static function remove(string $key, ?int $coroutineId = null): void { // TODO: Implement remove() method. + if (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } Coroutine::getContext($coroutineId)[$key] = null; unset(Coroutine::getContext($coroutineId)[$key]); }