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; } }