1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-16 11:27:14 +01:00
postgres/lib/Internal/CompletionQueue.php
Aaron Piotrowski f363b05b10
Automatically discard unconsumed rows
Rows are automatically read and discarded when the tuple result is destructed.
2017-08-03 00:17:38 -05:00

45 lines
959 B
PHP

<?php
namespace Amp\Postgres\Internal;
use Amp\Loop;
class CompletionQueue {
/** @var bool */
private $complete = false;
/** @var callable[] */
private $onComplete = [];
public function onComplete(callable $onComplete) {
if ($this->complete) {
$onComplete();
return;
}
$this->onComplete[] = $onComplete;
}
public function complete() {
if ($this->complete) {
return;
}
$this->complete = true;
foreach ($this->onComplete as $callback) {
try {
$callback();
} catch (\Throwable $exception) {
Loop::defer(function () use ($exception) {
throw $exception; // Rethrow to event loop error handler.
});
}
}
$this->onComplete = null;
}
public function isComplete(): bool {
return $this->complete;
}
}