PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor_prefixed / guzzlehttp / promises / src / Each.php

Each.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at vendor_prefixed/guzzlehttp/promises/src/Each.php

68 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace YoastSEO_Vendor\GuzzleHttp\Promise;
5
6 final class Each
7 {
8 /**
9 * Given an iterator that yields promises or values, returns a promise that
10 * is fulfilled with a null value when the iterator has been consumed or
11 * the aggregate promise has been fulfilled or rejected.
12 *
13 * $onFulfilled is a function that accepts the fulfilled value, iterator
14 * index, and the aggregate promise. The callback can invoke any necessary
15 * side effects and choose to resolve or reject the aggregate if needed.
16 *
17 * $onRejected is a function that accepts the rejection reason, iterator
18 * index, and the aggregate promise. The callback can invoke any necessary
19 * side effects and choose to resolve or reject the aggregate if needed.
20 *
21 * @param mixed $iterable Iterator or array to iterate over.
22 */
23 public static function of($iterable, ?callable $onFulfilled = null, ?callable $onRejected = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
24 {
25 $iterable = self::prepareIterable($iterable, __FUNCTION__);
26 return (new \YoastSEO_Vendor\GuzzleHttp\Promise\EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected]))->promise();
27 }
28 /**
29 * Like of, but only allows a certain number of outstanding promises at any
30 * given time.
31 *
32 * $concurrency may be an integer or a function that accepts the number of
33 * pending promises and returns a numeric concurrency limit value to allow
34 * for dynamic a concurrency size.
35 *
36 * @param mixed $iterable
37 * @param int|callable $concurrency
38 */
39 public static function ofLimit($iterable, $concurrency, ?callable $onFulfilled = null, ?callable $onRejected = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
40 {
41 $iterable = self::prepareIterable($iterable, __FUNCTION__);
42 return (new \YoastSEO_Vendor\GuzzleHttp\Promise\EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected, 'concurrency' => $concurrency]))->promise();
43 }
44 /**
45 * Like limit, but ensures that no promise in the given $iterable argument
46 * is rejected. If any promise is rejected, then the aggregate promise is
47 * rejected with the encountered rejection.
48 *
49 * @param mixed $iterable
50 * @param int|callable $concurrency
51 */
52 public static function ofLimitAll($iterable, $concurrency, ?callable $onFulfilled = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface
53 {
54 $iterable = self::prepareIterable($iterable, __FUNCTION__);
55 return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $aggregate) : void {
56 $aggregate->reject($reason);
57 });
58 }
59 private static function prepareIterable($iterable, string $method) : iterable
60 {
61 if (\is_iterable($iterable)) {
62 return $iterable;
63 }
64 \YoastSEO_Vendor\trigger_deprecation('guzzlehttp/promises', '2.5', 'Passing a non-iterable to %s::%s() is deprecated; guzzlehttp/promises 3.0 will require an iterable.', self::class, $method);
65 return [$iterable];
66 }
67 }
68