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) {
3030 makePromise ( this . promise ) ;
3131 }
3232
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 ;
3736
38- this . _result = new Array ( this . length ) ;
37+ this . _result = new Array ( this . length ) ;
3938
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 ) {
4145 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- }
4846 }
49- } else {
50- reject ( this . promise , validationError ( ) ) ;
5147 }
5248}
5349
54- function validationError ( ) {
55- return new Error ( 'Array Methods must be provided an Array' ) ;
56- } ;
57-
5850Enumerator . prototype . _enumerate = function ( ) {
5951 let { length, _input } = this ;
6052
Original file line number Diff line number Diff line change 11import Enumerator from '../enumerator' ;
2-
2+ import {
3+ isArray ,
4+ isMaybeThenable
5+ } from '../utils' ;
36/**
47 `Promise.all` accepts an array of promises, and returns a new promise which
58 is fulfilled with an array of fulfillment values for the passed promises, or
@@ -48,5 +51,9 @@ import Enumerator from '../enumerator';
4851 @static
4952*/
5053export 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+
5158 return new Enumerator ( this , entries ) . promise ;
5259}
You can’t perform that action at this time.
0 commit comments