PluginProbe
Media Cloud Sync / 1.0.3
Media Cloud Sync v1.0.3
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.0.3, at includes/sdk/s3/GuzzleHttp/Promise/Each.php

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