protected function resolve($value = null): void
    {
        if (~$this->state & AbstractPromise::PENDING) {
            return;
        }
        
        if ($value instanceof Promise) {
            $value->when(function (?\Throwable $e, $v = null): void {
                if ($e === null) {
                    $this->resolve($v);
                } else {
                    $this->fail($e);
                }
            });
            
            return;
        }
        
        $callbacks = $this->result;
        
        $this->state ^= AbstractPromise::PENDING | AbstractPromise::SUCCEEDED;
        $this->result = $value;
        
        if ($this instanceof Cancellable) {
            $this->context->unregisterCancellation($this);
        }
        
        if ($callbacks) {
            if (\is_array($callbacks)) {
                foreach ($callbacks as $callback) {
                    try {
                        $callback(null, $value);
                    } catch (\Throwable $e) {
                        $this->context->handleError($e);
                    }
                }
            } else {
                try {
                    $callbacks(null, $value);
                } catch (\Throwable $e) {
                    $this->context->handleError($e);
                }
            }
        }
    }
protected function resolve($value = null): void
    {
        if (~$this->state & AbstractPromise::PENDING) {
            return;
        }
        
        if ($value instanceof Promise) {
            $value->when(function (?\Throwable $e, $v = null): void {
                if ($e === null) {
                    $this->resolve($v);
                } else {
                    $this->fail($e);
                }
            });
            
            return;
        }
        
        $callbacks = $this->result;
        
        $this->state ^= AbstractPromise::PENDING | AbstractPromise::SUCCEEDED;
        $this->result = $value;
        
        if ($this instanceof Cancellable) {
            $this->context->unregisterCancellation($this);
        }
        
        if ($callbacks) {
            if (\is_array($callbacks)) {
                foreach ($callbacks as $callback) {
                    try {
                        $callback(null, $value);
                    } catch (\Throwable $e) {
                        $this->context->handleError($e);
                    }
                }
            } else {
                try {
                    $callbacks(null, $value);
                } catch (\Throwable $e) {
                    $this->context->handleError($e);
                }
            }
        }
    }
protected function resolve ( $ value = null ) : void { if ( ~ $ this -> state & AbstractPromise :: PENDING ) { return ; } if ( $ value instanceof Promise ) { $ value -> when ( function ( ? \ Throwable $ e , $ v = null ) : void { if ( $ e === null ) { $ this -> resolve ( $ v ) ; } else { $ this -> fail ( $ e ) ; } } ) ; return ; } $ callbacks = $ this -> result ; $ this -> state ^= AbstractPromise :: PENDING | AbstractPromise :: SUCCEEDED ; $ this -> result = $ value ; if ( $ this instanceof Cancellable ) { $ this -> context -> unregisterCancellation ( $ this ) ; } if ( $ callbacks ) { if ( \ is_array ( $ callbacks ) ) { foreach ( $ callbacks as $ callback ) { try { $ callback ( null , $ value ) ; } catch ( \ Throwable $ e ) { $ this -> context -> handleError ( $ e ) ; } } } else { try { $ callbacks ( null , $ value ) ; } catch ( \ Throwable $ e ) { $ this -> context -> handleError ( $ e ) ; } } } }
Resolve the promise with the given value.

Passing a promise as value will defer resolution until the promise resolves.
Resolve the promise with the given value .