lib/Promise.php
public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
    {
        // This new subPromise will be returned from this function, and will
        // be fulfilled with the result of the onFulfilled or onRejected event
        // handlers.
        $subPromise = new self();

        switch ($this->state) {
            case self::PENDING:
                // The operation is pending, so we keep a reference to the
                // event handlers so we can call them later.
                $this->subscribers[] = [$subPromise, $onFulfilled, $onRejected];
                break;
            case self::FULFILLED:
                // The async operation is already fulfilled, so we trigger the
                // onFulfilled callback asap.
                $this->invokeCallback($subPromise, $onFulfilled);
                break;
            case self::REJECTED:
                // The async operation failed, so we call the onRejected
                // callback asap.
                $this->invokeCallback($subPromise, $onRejected);
                break;
        }

        return $subPromise;
    }
public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
    {
        // This new subPromise will be returned from this function, and will
        // be fulfilled with the result of the onFulfilled or onRejected event
        // handlers.
        $subPromise = new self();

        switch ($this->state) {
            case self::PENDING:
                // The operation is pending, so we keep a reference to the
                // event handlers so we can call them later.
                $this->subscribers[] = [$subPromise, $onFulfilled, $onRejected];
                break;
            case self::FULFILLED:
                // The async operation is already fulfilled, so we trigger the
                // onFulfilled callback asap.
                $this->invokeCallback($subPromise, $onFulfilled);
                break;
            case self::REJECTED:
                // The async operation failed, so we call the onRejected
                // callback asap.
                $this->invokeCallback($subPromise, $onRejected);
                break;
        }

        return $subPromise;
    }
public function then ( callable $ onFulfilled = null , callable $ onRejected = null ) : Promise { // This new subPromise will be returned from this function, and will // be fulfilled with the result of the onFulfilled or onRejected event // handlers. $ subPromise = new self ( ) ; switch ( $ this -> state ) { case self :: PENDING : // The operation is pending, so we keep a reference to the // event handlers so we can call them later. $ this -> subscribers [ ] = [ $ subPromise , $ onFulfilled , $ onRejected ] ; break ; case self :: FULFILLED : // The async operation is already fulfilled, so we trigger the // onFulfilled callback asap. $ this -> invokeCallback ( $ subPromise , $ onFulfilled ) ; break ; case self :: REJECTED : // The async operation failed, so we call the onRejected // callback asap. $ this -> invokeCallback ( $ subPromise , $ onRejected ) ; break ; } return $ subPromise ; }
This method allows you to specify the callback that will be called after
the promise has been fulfilled or rejected.

Both arguments are optional.

This method returns a new promise, which can be used for chaining.
If either the onFulfilled or onRejected callback is called, you may
return a result from this callback.

If the result of this callback is yet another promise, the result of
_that_ promise will be used to set the result of the returned promise.

If either of the callbacks return any other value, the returned promise
is automatically fulfilled with that value.

If either of the callbacks throw an exception, the returned promise will
be rejected and the exception will be passed back.
This method allows you to specify the callback that will be called after the promise has been fulfilled or rejected .