1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-27 04:24:45 +01:00
postgres/lib/Internal/Operation.php
2017-05-15 23:28:37 -05:00

37 lines
689 B
PHP

<?php
namespace Amp\Postgres\Internal;
trait Operation {
/** @var bool */
private $complete = false;
/** @var callable[] */
private $onComplete = [];
public function __destruct() {
$this->complete();
}
public function onComplete(callable $onComplete) {
if ($this->complete) {
$onComplete();
return;
}
$this->onComplete[] = $onComplete;
}
private function complete() {
if ($this->complete) {
return;
}
$this->complete = true;
foreach ($this->onComplete as $callback) {
$callback();
}
$this->onComplete = null;
}
}