1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-30 04:29:12 +01:00

Only mark connection busy on transaction

Underlying handle will take care of ordering other operations.
This commit is contained in:
Aaron Piotrowski 2017-11-05 11:24:38 -06:00
parent 32369079e6
commit 4fc6425fd8
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -51,13 +51,7 @@ abstract class AbstractConnection implements Connection {
yield $this->busy->promise();
}
$this->busy = new Deferred;
try {
return $this->handle->{$methodName}(...$args);
} finally {
$this->release();
}
return $this->handle->{$methodName}(...$args);
}
/**
@ -110,12 +104,6 @@ abstract class AbstractConnection implements Connection {
*/
public function transaction(int $isolation = Transaction::COMMITTED): Promise {
return call(function () use ($isolation) {
while ($this->busy) {
yield $this->busy->promise();
}
$this->busy = new Deferred;
switch ($isolation) {
case Transaction::UNCOMMITTED:
yield $this->handle->query("BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
@ -137,6 +125,8 @@ abstract class AbstractConnection implements Connection {
throw new \Error("Invalid transaction type");
}
$this->busy = new Deferred;
$transaction = new Transaction($this->handle, $isolation);
$transaction->onComplete($this->release);
return $transaction;