@@ -68,11 +68,15 @@ function reject(\Throwable $reason): PromiseInterface
68
68
* will be an array containing the resolution values of each of the items in
69
69
* `$promisesOrValues`.
70
70
*
71
- * @param array $promisesOrValues
71
+ * @param iterable $promisesOrValues
72
72
* @return PromiseInterface
73
73
*/
74
- function all (array $ promisesOrValues ): PromiseInterface
74
+ function all (iterable $ promisesOrValues ): PromiseInterface
75
75
{
76
+ if (!\is_array ($ promisesOrValues )) {
77
+ $ promisesOrValues = \iterator_to_array ($ promisesOrValues );
78
+ }
79
+
76
80
if (!$ promisesOrValues ) {
77
81
return resolve ([]);
78
82
}
@@ -109,11 +113,15 @@ function ($mapped) use ($i, &$values, &$toResolve, $resolve): void {
109
113
* The returned promise will become **infinitely pending** if `$promisesOrValues`
110
114
* contains 0 items.
111
115
*
112
- * @param array $promisesOrValues
116
+ * @param iterable $promisesOrValues
113
117
* @return PromiseInterface
114
118
*/
115
- function race (array $ promisesOrValues ): PromiseInterface
119
+ function race (iterable $ promisesOrValues ): PromiseInterface
116
120
{
121
+ if (!\is_array ($ promisesOrValues )) {
122
+ $ promisesOrValues = \iterator_to_array ($ promisesOrValues );
123
+ }
124
+
117
125
if (!$ promisesOrValues ) {
118
126
return new Promise (function (): void {});
119
127
}
@@ -141,18 +149,22 @@ function race(array $promisesOrValues): PromiseInterface
141
149
* The returned promise will also reject with a `React\Promise\Exception\LengthException`
142
150
* if `$promisesOrValues` contains 0 items.
143
151
*
144
- * @param array $promisesOrValues
152
+ * @param iterable $promisesOrValues
145
153
* @return PromiseInterface
146
154
*/
147
- function any (array $ promisesOrValues ): PromiseInterface
155
+ function any (iterable $ promisesOrValues ): PromiseInterface
148
156
{
157
+ if (!\is_array ($ promisesOrValues )) {
158
+ $ promisesOrValues = \iterator_to_array ($ promisesOrValues );
159
+ }
160
+
149
161
$ len = \count ($ promisesOrValues );
150
162
151
163
if (!$ promisesOrValues ) {
152
164
return reject (
153
165
new Exception \LengthException (
154
166
\sprintf (
155
- 'Input array must contain at least 1 item but contains only %s item%s. ' ,
167
+ 'Must contain at least 1 item but contains only %s item%s. ' ,
156
168
$ len ,
157
169
1 === $ len ? '' : 's '
158
170
)
0 commit comments