if ($this->state === self::PENDING
) { $p =
new Promise(null,
[$this, 'cancel'
]);
$this->handlers
[] =
[$p,
$onFulfilled,
$onRejected];
$p->waitList =
$this->waitList;
$p->waitList
[] =
$this;
return $p;
} // Return a fulfilled promise and immediately invoke any callbacks.
if ($this->state === self::FULFILLED
) { $promise = Create::
promiseFor($this->result
);
return $onFulfilled ?
$promise->
then($onFulfilled) :
$promise;
} // It's either cancelled or rejected, so return a rejected promise
// and immediately invoke any callbacks.
$rejection = Create::
rejectionFor($this->result
);
return $onRejected ?
$rejection->
then(null,
$onRejected) :
$rejection;
}