PluginProbe
Media Cloud Sync / 1.3.11
Media Cloud Sync v1.3.11
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / sdk / s3 / GuzzleHttp / Promise / Each.php

Each.php in Media Cloud Sync 1.3.11, at includes/sdk/s3/GuzzleHttp/Promise/Each.php

57 lines 2.4 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 Dudlewebs\WPMCS\s3\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) : PromiseInterface
24 {
25 return (new EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected]))->promise();
26 }
27 /**
28 * Like of, but only allows a certain number of outstanding promises at any
29 * given time.
30 *
31 * $concurrency may be an integer or a function that accepts the number of
32 * pending promises and returns a numeric concurrency limit value to allow
33 * for dynamic a concurrency size.
34 *
35 * @param mixed $iterable
36 * @param int|callable $concurrency
37 */
38 public static function ofLimit($iterable, $concurrency, ?callable $onFulfilled = null, ?callable $onRejected = null) : PromiseInterface
39 {
40 return (new EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected, 'concurrency' => $concurrency]))->promise();
41 }
42 /**
43 * Like limit, but ensures that no promise in the given $iterable argument
44 * is rejected. If any promise is rejected, then the aggregate promise is
45 * rejected with the encountered rejection.
46 *
47 * @param mixed $iterable
48 * @param int|callable $concurrency
49 */
50 public static function ofLimitAll($iterable, $concurrency, ?callable $onFulfilled = null) : PromiseInterface
51 {
52 return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, PromiseInterface $aggregate) : void {
53 $aggregate->reject($reason);
54 });
55 }
56 }
57