Fix prepare for PooledStatement

This commit is contained in:
Aaron Piotrowski 2018-06-30 08:56:50 -05:00
parent dcbc634543
commit ed9d2b1002
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -72,7 +72,7 @@ abstract class AbstractPool implements Pool
$this->connections = $connections = new \SplObjectStorage;
$this->idle = $idle = new \SplQueue;
$this->prepare = coroutine($this->callableFromInstanceMethod("doPrepare"));
$this->prepare = coroutine($this->callableFromInstanceMethod("createStatement"));
$idleTimeout = &$this->idleTimeout;
@ -338,6 +338,13 @@ abstract class AbstractPool implements Pool
public function prepare(string $sql): Promise
{
return call(function () use ($sql) {
$statement = yield from $this->createStatement($sql);
return new PooledStatement($this, $statement, $this->prepare);
});
}
private function createStatement(string $sql): \Generator
{
$connection = yield from $this->pop();
\assert($connection instanceof Link);
@ -358,8 +365,7 @@ abstract class AbstractPool implements Pool
$this->push($connection);
});
return new PooledStatement($this, $statement, $this->prepare);
});
return $statement;
}
/**