From f91194b5c822750c54a42b1befdb9a6b24734a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 5 Jul 2021 10:52:26 +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 --- System/Abstracts/Pool.php | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/System/Abstracts/Pool.php b/System/Abstracts/Pool.php index 29b2d690..cb7e35fa 100644 --- a/System/Abstracts/Pool.php +++ b/System/Abstracts/Pool.php @@ -80,10 +80,10 @@ abstract class Pool extends Component $this->creates = -1; } else { $min = Config::get('databases.pool.min', 1); - $channel = $this->getChannel($name); - if ($channel->length() > $min) { + if (($length = $this->getChannel($name)->length()) > $min) { $this->flush($min); } + $this->debug("$length -> min length $min"); } } @@ -155,6 +155,9 @@ abstract class Pool extends Component if (Coroutine::getCid() === -1) { return; } + if ($this->creates === -1) { + $this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection'], $name); + } static::$_items[$name] = new Channel($max); $this->max = $max; } @@ -194,27 +197,15 @@ abstract class Pool extends Component return $connection; } } - if ($this->creates === -1 && !is_callable($callback)) { - $this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection'], $name); - } return $this->createClient($name, $callback); } /** - * @param Channel $channel - * @param $name - * @param mixed $callback + * @param string $name + * @param mixed $config + * @return mixed */ - private function createByCallback(Channel $channel, $name, mixed $callback): void - { - if ($this->creates === -1 && !is_callable($callback)) { - $this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']); - } - $channel->push($this->createClient($name, $callback)); - } - - abstract public function createClient(string $name, mixed $config): mixed;