This commit is contained in:
2021-09-07 14:47:44 +08:00
parent 8844131a0b
commit 72578e46b5
+5 -4
View File
@@ -122,8 +122,7 @@ class Pool extends Component
{ {
$channel = $this->getChannel($name); $channel = $this->getChannel($name);
if (!$channel->isEmpty()) { if (!$channel->isEmpty()) {
$connection = $channel->pop(); $connection = $this->maxIdleQuantity($channel);
defer(fn() => $this->maxIdleQuantity($channel));
if ($this->checkCanUse($name, $connection)) { if ($this->checkCanUse($name, $connection)) {
return $connection; return $connection;
} }
@@ -134,15 +133,17 @@ class Pool extends Component
/** /**
* @param $channel * @param $channel
* @return mixed
* @throws ConfigException * @throws ConfigException
* @throws Exception
*/ */
private function maxIdleQuantity($channel): void private function maxIdleQuantity($channel): mixed
{ {
$connection = $channel->pop();
$minx = Config::get('databases.pool.min', 1); $minx = Config::get('databases.pool.min', 1);
if ($channel->length() > $minx) { if ($channel->length() > $minx) {
$this->pop($channel, $minx); $this->pop($channel, $minx);
} }
return $connection;
} }