Amp\Internal\WhenQueue::push PHP Method

push() public method

Unrolls instances of self to avoid blowing up the call stack on resolution.
public push ( callable $callback )
$callback callable
    public function push(callable $callback)
    {
        if ($callback instanceof self) {
            $this->queue = \array_merge($this->queue, $callback->queue);
            return;
        }
        $this->queue[] = $callback;
    }

Usage Example

Example #1
0
 /**
  * @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);
 }