@@ -122,45 +122,13 @@ function race(array $promisesOrValues): PromiseInterface
122
122
*/
123
123
function any (array $ promisesOrValues ): PromiseInterface
124
124
{
125
- return some ($ promisesOrValues , 1 )
126
- ->then (function ($ val ) {
127
- return \array_shift ($ val );
128
- });
129
- }
130
-
131
- /**
132
- * Returns a promise that will resolve when `$howMany` of the supplied items in
133
- * `$promisesOrValues` resolve. The resolution value of the returned promise
134
- * will be an array of length `$howMany` containing the resolution values of the
135
- * triggering items.
136
- *
137
- * The returned promise will reject if it becomes impossible for `$howMany` items
138
- * to resolve (that is, when `(count($promisesOrValues) - $howMany) + 1` items
139
- * reject). The rejection value will be an array of
140
- * `(count($promisesOrValues) - $howMany) + 1` rejection reasons.
141
- *
142
- * The returned promise will also reject with a `React\Promise\Exception\LengthException`
143
- * if `$promisesOrValues` contains less items than `$howMany`.
144
- *
145
- * @param array $promisesOrValues
146
- * @param int $howMany
147
- * @return PromiseInterface
148
- */
149
- function some (array $ promisesOrValues , int $ howMany ): PromiseInterface
150
- {
151
- if ($ howMany < 1 ) {
152
- return resolve ([]);
153
- }
154
-
155
125
$ len = \count ($ promisesOrValues );
156
126
157
- if ($ len < $ howMany ) {
127
+ if (! $ promisesOrValues ) {
158
128
return reject (
159
129
new Exception \LengthException (
160
130
\sprintf (
161
- 'Input array must contain at least %d item%s but contains only %s item%s. ' ,
162
- $ howMany ,
163
- 1 === $ howMany ? '' : 's ' ,
131
+ 'Input array must contain at least 1 item but contains only %s item%s. ' ,
164
132
$ len ,
165
133
1 === $ len ? '' : 's '
166
134
)
@@ -170,37 +138,23 @@ function some(array $promisesOrValues, int $howMany): PromiseInterface
170
138
171
139
$ cancellationQueue = new Internal \CancellationQueue ();
172
140
173
- return new Promise (function ($ resolve , $ reject ) use ($ len , $ promisesOrValues , $ howMany , $ cancellationQueue ): void {
174
- $ toResolve = $ howMany ;
175
- $ toReject = ($ len - $ toResolve ) + 1 ;
176
- $ values = [];
141
+ return new Promise (function ($ resolve , $ reject ) use ($ len , $ promisesOrValues , $ cancellationQueue ): void {
142
+ $ toReject = $ len ;
177
143
$ reasons = [];
178
144
179
145
foreach ($ promisesOrValues as $ i => $ promiseOrValue ) {
180
- $ fulfiller = function ($ val ) use ($ i , &$ values , &$ toResolve , $ toReject , $ resolve ): void {
181
- if ($ toResolve < 1 || $ toReject < 1 ) {
182
- return ;
183
- }
184
-
185
- $ values [$ i ] = $ val ;
186
-
187
- if (0 === --$ toResolve ) {
188
- $ resolve ($ values );
189
- }
146
+ $ fulfiller = function ($ val ) use ($ resolve ): void {
147
+ $ resolve ($ val );
190
148
};
191
149
192
- $ rejecter = function (\Throwable $ reason ) use ($ i , &$ reasons , &$ toReject , $ toResolve , $ reject ): void {
193
- if ($ toResolve < 1 || $ toReject < 1 ) {
194
- return ;
195
- }
196
-
150
+ $ rejecter = function (\Throwable $ reason ) use ($ i , &$ reasons , &$ toReject , $ reject ): void {
197
151
$ reasons [$ i ] = $ reason ;
198
152
199
153
if (0 === --$ toReject ) {
200
154
$ reject (
201
155
new CompositeException (
202
156
$ reasons ,
203
- 'Too many promises rejected. '
157
+ 'All promises rejected. '
204
158
)
205
159
);
206
160
}
0 commit comments