This commit is contained in:
2021-07-05 11:03:34 +08:00
parent 9ea0b9d34b
commit 6cdf8052e6
+7 -8
View File
@@ -83,6 +83,8 @@ abstract class Pool extends Component
if (($length = $this->getChannel($name)->length()) > $min) { if (($length = $this->getChannel($name)->length()) > $min) {
$this->debug("$length -> min length $min"); $this->debug("$length -> min length $min");
$this->flush($min); $this->flush($min);
} else {
$this->debug("$length -> min length $min");
} }
} }
} }
@@ -170,11 +172,10 @@ abstract class Pool extends Component
*/ */
private function getChannel($name): Channel private function getChannel($name): Channel
{ {
$channel = static::$_items[$name] ?? new Channel(Config::get('databases.pool.max', 10)); if (!isset(static::$_items[$name])) {
if (!((static::$_items[$name] ?? null) instanceof Channel)) { static::$_items[$name] = new Channel(Config::get('databases.pool.max', 10));
static::$_items[$name] = $channel;
} }
return $channel; return static::$_items[$name];
} }
@@ -294,16 +295,14 @@ abstract class Pool extends Component
/** /**
* @param string $name * @param string $name
* @param mixed $client * @param mixed $client
* @throws ConfigException
*/ */
public function push(string $name, mixed $client) public function push(string $name, mixed $client)
{ {
if (Coroutine::getCid() === -1) { if (Coroutine::getCid() === -1) {
return; return;
} }
$channel = static::$_items[$name] ?? new Channel($this->max); $channel = $this->getChannel($name);
if (!isset(static::$_items[$name])) {
static::$_items[$name] = $channel;
}
if (!$channel->isFull()) { if (!$channel->isFull()) {
$channel->push($client); $channel->push($client);
} }