React\Promise\Promise::then PHP Method

then() public method

public then ( callable $onFulfilled = null, callable $onRejected = null )
$onFulfilled callable
$onRejected callable
    public function then(callable $onFulfilled = null, callable $onRejected = null)
    {
        if (null !== $this->result) {
            return $this->result()->then($onFulfilled, $onRejected);
        }
        if (null === $this->canceller) {
            return new static($this->resolver($onFulfilled, $onRejected));
        }
        $this->requiredCancelRequests++;
        return new static($this->resolver($onFulfilled, $onRejected), function () {
            if (++$this->cancelRequests < $this->requiredCancelRequests) {
                return;
            }
            $this->cancel();
        });
    }

Usage Example

Example #1
0
 /**
  * Handle on session start
  * 
  * @param \Thruway\AbstractSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $this->thePromise->then(function () use($session) {
         $this->getCaller()->call($session, 'com.example.thefunction0', [])->then(function ($res) {
             var_dump($res);
         });
     });
 }
All Usage Examples Of React\Promise\Promise::then