| @@ -21,8 +21,9 @@ | ||
| 21 | 21 | * @param mixed $iterable Iterator or array to iterate over. |
| 22 | 22 | */ |
| 23 | 23 | public static function of($iterable, ?callable $onFulfilled = null, ?callable $onRejected = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface |
| 24 | 24 | { |
| 25 | + $iterable = self::prepareIterable($iterable, __FUNCTION__); | |
| 25 | 26 | return (new \YoastSEO_Vendor\GuzzleHttp\Promise\EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected]))->promise(); |
| 26 | 27 | } |
| 27 | 28 | /** |
| 28 | 29 | * Like of, but only allows a certain number of outstanding promises at any |
| @@ -36,8 +37,9 @@ | ||
| 36 | 37 | * @param int|callable $concurrency |
| 37 | 38 | */ |
| 38 | 39 | public static function ofLimit($iterable, $concurrency, ?callable $onFulfilled = null, ?callable $onRejected = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface |
| 39 | 40 | { |
| 41 | + $iterable = self::prepareIterable($iterable, __FUNCTION__); | |
| 40 | 42 | return (new \YoastSEO_Vendor\GuzzleHttp\Promise\EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected, 'concurrency' => $concurrency]))->promise(); |
| 41 | 43 | } |
| 42 | 44 | /** |
| 43 | 45 | * Like limit, but ensures that no promise in the given $iterable argument |
| @@ -48,9 +50,18 @@ | ||
| 48 | 50 | * @param int|callable $concurrency |
| 49 | 51 | */ |
| 50 | 52 | public static function ofLimitAll($iterable, $concurrency, ?callable $onFulfilled = null) : \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface |
| 51 | 53 | { |
| 54 | + $iterable = self::prepareIterable($iterable, __FUNCTION__); | |
| 52 | 55 | return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, \YoastSEO_Vendor\GuzzleHttp\Promise\PromiseInterface $aggregate) : void { |
| 53 | 56 | $aggregate->reject($reason); |
| 54 | 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]; | |
| 55 | 66 | } |
| 56 | 67 | } |