92    function then(callable $onFulfilled = 
null, callable $onRejected = 
null) {
 
   97        $subPromise = 
new self();
 
   99        switch ($this->state) {
 
  103                $this->subscribers[] = [$subPromise, $onFulfilled, $onRejected];
 
  131        return $this->
then(
null, $onRejected);
 
  142        if ($this->state !== self::PENDING) {
 
  147        foreach ($this->subscribers as $subscriber) {
 
  162        if ($this->state !== self::PENDING) {
 
  166        $this->value = $reason;
 
  167        foreach ($this->subscribers as $subscriber) {
 
  190        while ($this->state === self::PENDING) {
 
  193                throw new \LogicException(
'There were no more events in the loop. This promise will never be fulfilled.');
 
  202        if ($this->state === self::FULFILLED) {
 
  209            if ($reason instanceof Exception) {
 
  211            } elseif (is_scalar($reason)) {
 
  212                throw new Exception($reason);
 
  214                $type = is_object($reason) ? get_class($reason) : gettype($reason);
 
  215                throw new Exception(
'Promise was rejected with reason of type: ' . 
$type);
 
  260            if (is_callable($callBack)) {
 
  263                    $result = $callBack($this->value);
 
  269                        $result->then([$subPromise, 
'fulfill'], [$subPromise, 
'reject']);
 
  275                } 
catch (Exception $e) {
 
  281                if ($this->state === self::FULFILLED) {
 
  282                    $subPromise->
fulfill($this->value);
 
  284                    $subPromise->
reject($this->value);
 
  299    function error(callable $onRejected) {
 
  314    static function all(array $promises) {
 
An exception for terminatinating execution or to throw for unit testing.
tick($block=false)
Executes all pending events.
nextTick(callable $cb)
Runs a function immediately at the next iteration of the loop.
This exception is thrown when the user tried to reject or fulfill a promise, after either of these ac...
An implementation of the Promise pattern.
static all(array $promises)
Deprecated.
fulfill($value=null)
Marks this promise as fulfilled and sets its return value.
invokeCallback(Promise $subPromise, callable $callBack=null)
This method is used to call either an onFulfilled or onRejected callback.
const FULFILLED
The asynchronous operation has completed, and has a result.
__construct(callable $executor=null)
Creates the promise.
otherwise(callable $onRejected)
Add a callback for when this promise is rejected.
const PENDING
The asynchronous operation is pending.
then(callable $onFulfilled=null, callable $onRejected=null)
This method allows you to specify the callback that will be called after the promise has been fulfill...
const REJECTED
The asynchronous operation has completed with an error.
reject($reason=null)
Marks this promise as rejected, and set it's rejection reason.
error(callable $onRejected)
Alias for 'otherwise'.
wait()
Stops execution until this promise is resolved.