public static function race($promisesOrValues)
    {
        $cancellationQueue = new CancellationQueue();

        return new Promise(function($resolve, $reject, $cancel) use($promisesOrValues, $cancellationQueue) {
            self::doResolve($promisesOrValues)
                ->done(function($array) use($resolve, $reject, $cancel, $cancellationQueue) {
                    if (!is_array($array) || !$array)
                    {
                        $resolve();
                        return;
                    }

                    $fulfiller = function($value) use($resolve, $cancellationQueue) {
                        $resolve($value);
                        $cancellationQueue();
                    };

                    $rejecter = function($reason) use($reject, $cancellationQueue) {
                        $reject($reason);
                        $cancellationQueue();
                    };

                    foreach ($array as $promiseOrValue)
                    {
                        $cancellationQueue->enqueue($promiseOrValue);

                        self::doResolve($promiseOrValue)
                            ->done($fulfiller, $rejecter, $cancel);
                    }
                }, $reject, $cancel);
        }, $cancellationQueue);
    }
public static function race($promisesOrValues)
    {
        $cancellationQueue = new CancellationQueue();

        return new Promise(function($resolve, $reject, $cancel) use($promisesOrValues, $cancellationQueue) {
            self::doResolve($promisesOrValues)
                ->done(function($array) use($resolve, $reject, $cancel, $cancellationQueue) {
                    if (!is_array($array) || !$array)
                    {
                        $resolve();
                        return;
                    }

                    $fulfiller = function($value) use($resolve, $cancellationQueue) {
                        $resolve($value);
                        $cancellationQueue();
                    };

                    $rejecter = function($reason) use($reject, $cancellationQueue) {
                        $reject($reason);
                        $cancellationQueue();
                    };

                    foreach ($array as $promiseOrValue)
                    {
                        $cancellationQueue->enqueue($promiseOrValue);

                        self::doResolve($promiseOrValue)
                            ->done($fulfiller, $rejecter, $cancel);
                    }
                }, $reject, $cancel);
        }, $cancellationQueue);
    }
public static function race ( $ promisesOrValues ) { $ cancellationQueue = new CancellationQueue ( ) ; return new Promise ( function ( $ resolve , $ reject , $ cancel ) use ( $ promisesOrValues , $ cancellationQueue ) { self :: doResolve ( $ promisesOrValues ) -> done ( function ( $ array ) use ( $ resolve , $ reject , $ cancel , $ cancellationQueue ) { if ( ! is_array ( $ array ) || ! $ array ) { $ resolve ( ) ; return ; } $ fulfiller = function ( $ value ) use ( $ resolve , $ cancellationQueue ) { $ resolve ( $ value ) ; $ cancellationQueue ( ) ; } ; $ rejecter = function ( $ reason ) use ( $ reject , $ cancellationQueue ) { $ reject ( $ reason ) ; $ cancellationQueue ( ) ; } ; foreach ( $ array as $ promiseOrValue ) { $ cancellationQueue -> enqueue ( $ promiseOrValue ) ; self :: doResolve ( $ promiseOrValue ) -> done ( $ fulfiller , $ rejecter , $ cancel ) ; } } , $ reject , $ cancel ) ; } , $ cancellationQueue ) ; }
Initiate a competitive race that allows one winner.

Initiate a competitive race that allows one winner. Returns a promise which is resolved in the same way
the first settled promise resolves.

@param PromiseInterface[]|mixed[] $promisesOrValues
@return PromiseInterface
@resolves mixed
@rejects Error|Exception|string|null
@cancels Error|Exception|string|null
Initiate a competitive race that allows one winner .