public function statement($sql, $params = null) { $command = new Command($sql, $params); $deferred = new Deferred(); $this->pool->withConnection(function (Connection $connection) use($command, $deferred) { $sql = $command->getPreparedQuery($connection); $connection->query($sql, MYSQLI_ASYNC); $this->conns[$connection->id] = ['mysqli' => $connection, 'deferred' => $deferred]; }); return $deferred->promise(); }
public function testIdenticalConnections() { $pool = new ConnectionPool(); $connection = null; $pool->withConnection(function ($conn) use($pool, &$connection) { $connection = $conn; $pool->releaseConnection($conn); }); $pool->withConnection(function ($conn) use($pool, $connection) { $this->assertSame($connection, $conn); $pool->releaseConnection($conn); }); }