Amp\Internal\Placeholder::when PHP Method

when() public method

See also: Interop\Async\Promise::when()
public when ( callable $onResolved )
$onResolved callable
    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);
    }