complete) { $onComplete(); return; } $this->onComplete[] = $onComplete; } private 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; } }