This commit is contained in:
2021-04-27 14:00:20 +08:00
parent 1a76b21143
commit aeb31eefac
2 changed files with 10 additions and 3 deletions
+6 -2
View File
@@ -170,8 +170,9 @@ abstract class Pool extends Component
}
$time = microtime(true);
if (!$this->hasItem($name)) {
$this->createByCallback($name, $callback);
return $this->createByCallback($name, $callback);
}
$connection = $this->_items[$name]->pop(0.01);
if (microtime(true) - $time >= 0.007) {
$this->warning('Worker #' . env('worker') . ' get client use time ' . (microtime(true) - $time));
@@ -187,14 +188,17 @@ abstract class Pool extends Component
/**
* @param $name
* @param mixed $callback
* @return mixed
* @throws Exception
*/
private function createByCallback($name, mixed $callback)
private function createByCallback($name, mixed $callback): mixed
{
if ($this->creates === -1 && !is_callable($callback)) {
$this->creates = Timer::tick(1000, [$this, 'Heartbeat_detection']);
}
return $this->createClient($name, $callback);
if (!Context::hasContext('create::client::ing::' . $name)) {
$this->push($name, $this->createClient($name, $callback));
Context::remove('create::client::ing::' . $name);