From d5e0bea13aea000edc4696e8f0739759d2185cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 19 Jan 2021 18:44:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gii/Gii.php | 11 ++++------- System/Abstracts/Pool.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Gii/Gii.php b/Gii/Gii.php index e5f2f2e7..54434552 100644 --- a/Gii/Gii.php +++ b/Gii/Gii.php @@ -56,22 +56,19 @@ class Gii */ public function run(?Connection $db, $input): array { - return [ - go(function () use ($db, $input) { - return $this->gen($input, $db); - }) - ]; + return $this->gen($input, $db); } /** * @param $input * @param $db - * @return array|string[] + * @return array * @throws ComponentException * @throws ConfigException + * @throws Exception */ - public function gen($input, $db) + public function gen($input, $db): array { $this->input = $input; if (!empty($db)) $this->db = $db; diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index c41ce559..96fdbd45 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -35,6 +35,9 @@ abstract class Pool extends Component if (isset($this->_items[$name]) && $this->_items[$name] instanceof Channel) { return; } + if (!Context::inCoroutine()) { + return; + } $this->_items[$name] = new Channel((int)$max); $this->max = (int)$max; } @@ -46,6 +49,9 @@ abstract class Pool extends Component */ protected function get($name): array { + if (!Context::inCoroutine()) { + return [0, null]; + } [$timeout, $connection] = $this->_items[$name]->pop(30); if (!$this->checkCanUse($name, $timeout, $connection)) { unset($client); @@ -144,6 +150,9 @@ abstract class Pool extends Component */ public function size(string $name): mixed { + if (!Context::inCoroutine()) { + return 0; + } if (!isset($this->_items[$name])) { return 0; } @@ -157,6 +166,9 @@ abstract class Pool extends Component */ public function push(string $name, mixed $client) { + if (!Context::inCoroutine()) { + return; + } if (!$this->_items[$name]->isFull()) { $this->_items[$name]->push([time(), $client]); } @@ -170,6 +182,9 @@ abstract class Pool extends Component */ public function clean(string $name) { + if (!Context::inCoroutine()) { + return; + } if (!isset($this->_items[$name])) { return; }