File tree Expand file tree Collapse file tree 2 files changed +18
-19
lines changed Expand file tree Collapse file tree 2 files changed +18
-19
lines changed Original file line number Diff line number Diff line change @@ -30,31 +30,23 @@ function Enumerator(Constructor, input) {
30
30
makePromise ( this . promise ) ;
31
31
}
32
32
33
- if ( isArray ( input ) ) {
34
- this . _input = input ;
35
- this . length = input . length ;
36
- this . _remaining = input . length ;
33
+ this . _input = input ;
34
+ this . length = input . length ;
35
+ this . _remaining = input . length ;
37
36
38
- this . _result = new Array ( this . length ) ;
37
+ this . _result = new Array ( this . length ) ;
39
38
40
- if ( this . length === 0 ) {
39
+ if ( this . length === 0 ) {
40
+ fulfill ( this . promise , this . _result ) ;
41
+ } else {
42
+ this . length = this . length || 0 ;
43
+ this . _enumerate ( ) ;
44
+ if ( this . _remaining === 0 ) {
41
45
fulfill ( this . promise , this . _result ) ;
42
- } else {
43
- this . length = this . length || 0 ;
44
- this . _enumerate ( ) ;
45
- if ( this . _remaining === 0 ) {
46
- fulfill ( this . promise , this . _result ) ;
47
- }
48
46
}
49
- } else {
50
- reject ( this . promise , validationError ( ) ) ;
51
47
}
52
48
}
53
49
54
- function validationError ( ) {
55
- return new Error ( 'Array Methods must be provided an Array' ) ;
56
- } ;
57
-
58
50
Enumerator . prototype . _enumerate = function ( ) {
59
51
let { length, _input } = this ;
60
52
Original file line number Diff line number Diff line change 1
1
import Enumerator from '../enumerator' ;
2
-
2
+ import {
3
+ isArray ,
4
+ isMaybeThenable
5
+ } from '../utils' ;
3
6
/**
4
7
`Promise.all` accepts an array of promises, and returns a new promise which
5
8
is fulfilled with an array of fulfillment values for the passed promises, or
@@ -48,5 +51,9 @@ import Enumerator from '../enumerator';
48
51
@static
49
52
*/
50
53
export default function all ( entries ) {
54
+ if ( ! isArray ( entries ) ) {
55
+ return new Constructor ( ( _ , reject ) => reject ( new TypeError ( 'You must pass an array to all.' ) ) ) ;
56
+ }
57
+
51
58
return new Enumerator ( this , entries ) . promise ;
52
59
}
You can’t perform that action at this time.
0 commit comments