/** * @see \Interop\Async\Promise::when() */ public function when(callable $onResolved) { if ($this->resolved) { if ($this->result instanceof Promise) { $this->result->when($onResolved); return; } try { $onResolved(null, $this->result); } catch (\Throwable $exception) { Loop::defer(static function () use($exception) { throw $exception; }); } return; } if (null === $this->onResolved) { $this->onResolved = $onResolved; return; } if (!$this->onResolved instanceof WhenQueue) { $this->onResolved = new WhenQueue($this->onResolved); } $this->onResolved->push($onResolved); }