public function addConnection()
{
\Amp\immediately(function () {
if (count($this->connections) >= $this->limit) {
return;
}
$this->connections[] = $conn = new Connection($this->config);
end($this->connections);
$this->connectionMap[spl_object_hash($conn)] = key($this->connections);
$this->connectionPromise = $conn->connect();
$this->connectionPromise->when(function ($error) use($conn) {
if ($error) {
$this->unmapConnection($conn);
if (empty($this->connections)) {
$this->virtualConnection->fail($error);
}
return;
}
if ($this->config->charset != "utf8mb4" || $this->config->collate != "" && $this->config->collate != "utf8mb4_general_ci") {
$conn->setCharset($this->config->charset, $this->config->collate);
}
});
});
}