settled example

$this->mutex = false;
        $this->aggregate = new Promise(function D): void {
            if ($this->checkIfFinished()) {
                return;
            }
            reset($this->pending);
            // Consume a potentially fluctuating list of promises while             // ensuring that indexes are maintained (precluding array_shift).             while ($promise = current($this->pending)) {
                next($this->pending);
                $promise->wait();
                if (Is::settled($this->aggregate)) {
                    return;
                }
            }
        });

        // Clear the references when the promise is resolved.         $clearFn = function D): void {
            $this->iterable = $this->concurrency = $this->pending = null;
            $this->onFulfilled = $this->onRejected = null;
            $this->nextPendingIndex = 0;
        };

        

    private static function callHandler(int $index$value, array $handler): void
    {
        /** @var PromiseInterface $promise */
        $promise = $handler[0];

        // The promise may have been cancelled or resolved before placing         // this thunk in the queue.         if (Is::settled($promise)) {
            return;
        }

        try {
            if (isset($handler[$index])) {
                /* * If $f throws an exception, then $handler will be in the exception * stack trace. Since $handler contains a reference to the callable * itself we get a circular reference. We clear the $handler * here to avoid that memory leak. */
                

    public static function some(int $count$promises): PromiseInterface
    {
        $results = [];
        $rejections = [];

        return Each::of(
            $promises,
            function D$value$idx, PromiseInterface $p) use (&$results$count): void {
                if (Is::settled($p)) {
                    return;
                }
                $results[$idx] = $value;
                if (count($results) >= $count) {
                    $p->resolve(null);
                }
            },
            function D$reason) use (&$rejections): void {
                $rejections[] = $reason;
            }
        )->then(
            
Home | Imprint | This part of the site doesn't use cookies.