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Rҍ}!CձMI1W,7uAydq -ǀ2'?ƗG N1/a@`:WIGC 9&;&#zP¡e K|=³ۛ?%sSpsB\d^ m/FqG>C\g_&O#]"[6N]9~raHk\~`j{r~,pfùt@$.z ΓfqK-JDR7P?3,|`v&'ժ$+J޶??Lzt@[gqzOmxTi2R=G;COޓ=z3ݚiXof+Z!R/}voOQ(8x|,mw5ɵKmH9k]0gI2 LD8{} Y@f"dJ4:N4^:o#:\daTP45L|g4|Nz~9AGߟ`8 kcqB-UhFǙЇ:dZbetO(UpYYByCyu[n覛? O ѧQ:N'vWt${V @6*)#[<J\:}nN>8,yݒ33WRQ8ӧ|ĔZ?40ct?t) 9p> *v|JʻwMH nѩS86-KFiKjkŌ'h RI"281V[~5|.ڂ}6Z$OW*9 e9džOW7f%g]WJhGJ㩬]麛V,"3Wdk W1j.ŰFgY]e0-WHC2@bBM)}:m}7ETj,fuH>|vHa|RA$ha!~+#8V,ðKqfطq|,_69霄φYB *eV1(8cui 9 g+5 I L~mM"Ǒ^6M9H2"einal array. If any promise in the array * rejects, the returned promise is rejected with the rejection reason. * * @param mixed $promises Promises or values. * @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution. */ public static function all($promises, bool $recursive = false): PromiseInterface { $results = []; $promise = Each::of( $promises, function ($value, $idx) use (&$results): void { $results[$idx] = $value; }, function ($reason, $idx, Promise $aggregate): void { $aggregate->reject($reason); } )->then(function () use (&$results) { ksort($results); return $results; }); if (true === $recursive) { $promise = $promise->then(function ($results) use ($recursive, &$promises) { foreach ($promises as $promise) { if (Is::pending($promise)) { return self::all($promises, $recursive); } } return $results; }); } return $promise; } /** * Initiate a competitive race between multiple promises or values (values * will become immediately fulfilled promises). * * When count amount of promises have been fulfilled, the returned promise * is fulfilled with an array that contains the fulfillment values of the * winners in order of resolution. * * This promise is rejected with a {@see AggregateException} if the number * of fulfilled promises is less than the desired $count. * * @param int $count Total number of promises. * @param mixed $promises Promises or values. */ public static function some(int $count, $promises): PromiseInterface { $results = []; $rejections = []; return Each::of( $promises, function ($value, $idx, PromiseInterface $p) use (&$results, $count): void { if (Is::settled($p)) { return; } $results[$idx] = $value; if (count($results) >= $count) { $p->resolve(null); } }, function ($reason) use (&$rejections): void { $rejections[] = $reason; } )->then( function () use (&$results, &$rejections, $count) { if (count($results) !== $count) { throw new AggregateException( 'Not enough promises to fulfill count', $rejections ); } ksort($results); return array_values($results); } ); } /** * Like some(), with 1 as count. However, if the promise fulfills, the * fulfillment value is not an array of 1 but the value directly. * * @param mixed $promises Promises or values. */ public static function any($promises): PromiseInterface { return self::some(1, $promises)->then(function ($values) { return $values[0]; }); } /** * Returns a promise that is fulfilled when all of the provided promises have * been fulfilled or rejected. * * The returned promise is fulfilled with an array of inspection state arrays. * * @see inspect for the inspection state array format. * * @param mixed $promises Promises or values. */ public static function settle($promises): PromiseInterface { $results = []; return Each::of( $promises, function ($value, $idx) use (&$results): void { $results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value]; }, function ($reason, $idx) use (&$results): void { $results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason]; } )->then(function () use (&$results) { ksort($results); return $results; }); } }