File tree Expand file tree Collapse file tree 5 files changed +27
-7
lines changed Expand file tree Collapse file tree 5 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
37
37
- Always convert promises through ` PromiseAdapter::convertThenable() ` before calling ` ->then() ` on them
38
38
- Use ` JSON_THROW_ON_ERROR ` in ` json_encode() `
39
39
- Validate some internal invariants through ` assert() `
40
+ - ` PromiseAdapter::all() ` accepts ` iterable `
40
41
41
42
### Added
42
43
Original file line number Diff line number Diff line change 8
8
use Amp \Promise as AmpPromise ;
9
9
use Amp \Success ;
10
10
use function array_replace ;
11
+ use function assert ;
11
12
use GraphQL \Executor \Promise \Promise ;
12
13
use GraphQL \Executor \Promise \PromiseAdapter ;
14
+ use function is_array ;
13
15
use Throwable ;
14
16
15
17
class AmpPromiseAdapter implements PromiseAdapter
@@ -77,8 +79,13 @@ public function createRejected(Throwable $reason): Promise
77
79
return new Promise ($ promise , $ this );
78
80
}
79
81
80
- public function all (array $ promisesOrValues ): Promise
82
+ public function all (iterable $ promisesOrValues ): Promise
81
83
{
84
+ assert (
85
+ is_array ($ promisesOrValues ),
86
+ 'AmpPromiseAdapter::all(): Argument #1 ($promisesOrValues) must be of type array '
87
+ );
88
+
82
89
/** @var array<AmpPromise<mixed>> $promises */
83
90
$ promises = [];
84
91
foreach ($ promisesOrValues as $ key => $ item ) {
Original file line number Diff line number Diff line change @@ -52,8 +52,13 @@ public function createRejected(Throwable $reason): Promise
52
52
return new Promise ($ promise , $ this );
53
53
}
54
54
55
- public function all (array $ promisesOrValues ): Promise
55
+ public function all (iterable $ promisesOrValues ): Promise
56
56
{
57
+ assert (
58
+ is_array ($ promisesOrValues ),
59
+ 'ReactPromiseAdapter::all(): Argument #1 ($promisesOrValues) must be of type array '
60
+ );
61
+
57
62
// TODO: rework with generators when PHP minimum required version is changed to 5.5+
58
63
59
64
foreach ($ promisesOrValues as &$ promiseOrValue ) {
Original file line number Diff line number Diff line change 2
2
3
3
namespace GraphQL \Executor \Promise \Adapter ;
4
4
5
+ use function assert ;
5
6
use function count ;
6
7
use GraphQL \Deferred ;
7
8
use GraphQL \Error \InvariantViolation ;
8
9
use GraphQL \Executor \Promise \Promise ;
9
10
use GraphQL \Executor \Promise \PromiseAdapter ;
10
11
use GraphQL \Utils \Utils ;
12
+ use function is_array ;
11
13
use Throwable ;
12
14
13
15
/**
@@ -72,8 +74,13 @@ public function createRejected(Throwable $reason): Promise
72
74
return new Promise ($ promise ->reject ($ reason ), $ this );
73
75
}
74
76
75
- public function all (array $ promisesOrValues ): Promise
77
+ public function all (iterable $ promisesOrValues ): Promise
76
78
{
79
+ assert (
80
+ is_array ($ promisesOrValues ),
81
+ 'SyncPromiseAdapter::all(): Argument #1 ($promisesOrValues) must be of type array '
82
+ );
83
+
77
84
$ all = new SyncPromise ();
78
85
79
86
$ total = count ($ promisesOrValues );
Original file line number Diff line number Diff line change @@ -63,12 +63,12 @@ public function createFulfilled($value = null): Promise;
63
63
public function createRejected (Throwable $ reason ): Promise ;
64
64
65
65
/**
66
- * Given an array of promises (or values), returns a promise that is fulfilled when all the
67
- * items in the array are fulfilled.
66
+ * Given an iterable of promises (or values), returns a promise that is fulfilled when all the
67
+ * items in the iterable are fulfilled.
68
68
*
69
- * @param array <Promise|mixed> $promisesOrValues
69
+ * @param iterable <Promise|mixed> $promisesOrValues
70
70
*
71
71
* @api
72
72
*/
73
- public function all (array $ promisesOrValues ): Promise ;
73
+ public function all (iterable $ promisesOrValues ): Promise ;
74
74
}
You can’t perform that action at this time.
0 commit comments