mirror of
https://github.com/danog/postgres.git
synced 2024-12-16 11:27:14 +01:00
f363b05b10
Rows are automatically read and discarded when the tuple result is destructed.
45 lines
959 B
PHP
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;
|
|
}
|
|
}
|