This commit is contained in:
2021-07-05 15:49:37 +08:00
parent 74bcdf257e
commit 1a012150ce
5 changed files with 317 additions and 303 deletions
+19 -3
View File
@@ -113,10 +113,14 @@ class Connection extends Component
if (($pdo = Context::getContext($coroutineName)) instanceof PDO) {
return $pdo;
}
/** @var PDO $connections */
$connections = $this->getPool()->getFromChannel($coroutineName);
if (empty($connections)) {
if (Coroutine::getCid() === -1) {
$connections = $this->createClient($coroutineName, $config);
} else {
/** @var PDO $connections */
$connections = $this->getPool()->getFromChannel($coroutineName);
if (empty($connections)) {
$connections = $this->createClient($coroutineName, $config);
}
}
if ($number = Context::getContext('begin_' . $coroutineName, Coroutine::getCid())) {
$number > 0 && $connections->beginTransaction();
@@ -125,6 +129,18 @@ class Connection extends Component
}
/**
* @param $name
* @param $isMaster
* @param $max
* @throws Exception
*/
public function initConnections($name, $isMaster, $max)
{
$this->getPool()->initConnections($name, $isMaster, $max);
}
/**
* @param string $name
* @param mixed $config