Future::resolve PHP Méthode

resolve() public méthode

public resolve ( $value )
    public function resolve($value)
    {
        if ($value === $this) {
            $this->reject(new TypeError('Self resolution'));
            return;
        }
        if (isFuture($value)) {
            $value->fill($this);
            return;
        }
        if ($value !== NULL and is_object($value) or is_string($value)) {
            if (method_exists($value, 'then')) {
                $then = array($value, 'then');
                $notrun = true;
                $self = $this;
                try {
                    call_user_func($then, function ($y) use(&$notrun, $self) {
                        if ($notrun) {
                            $notrun = false;
                            $self->resolve($y);
                        }
                    }, function ($r) use(&$notrun, $self) {
                        if ($notrun) {
                            $notrun = false;
                            $self->reject($r);
                        }
                    });
                } catch (UncatchableException $e) {
                    throw $e->getPrevious();
                } catch (Exception $e) {
                    if ($notrun) {
                        $notrun = false;
                        $this->reject($e);
                    }
                } catch (Throwable $e) {
                    if ($notrun) {
                        $notrun = false;
                        $this->reject($e);
                    }
                }
                return;
            }
        }
        if ($this->state === self::PENDING) {
            $this->state = self::FULFILLED;
            $this->value = $value;
            while (count($this->subscribers) > 0) {
                $subscriber = array_shift($this->subscribers);
                $this->privateResolve($subscriber['onfulfill'], $subscriber['next'], $value);
            }
        }
    }

Usage Example

Exemple #1
0
 private function resolveFuture($key, Future $future)
 {
     $result = $future->resolve();
     $master = $this->getMaster();
     $master->write(array('type' => 'RSLV', 'key' => $key, 'err' => $result[0], 'stdout' => $result[1], 'stderr' => $result[2]));
     unset($this->exec[$key]);
 }
All Usage Examples Of Future::resolve