File tree 1 file changed +2
-5
lines changed
1 file changed +2
-5
lines changed Original file line number Diff line number Diff line change @@ -40,18 +40,15 @@ export const $q = {
40
40
/** Like Promise.all(), but also supports object key/promise notation like $q */
41
41
all : ( promises : { [ key : string ] : Promise < any > } | Promise < any > [ ] ) => {
42
42
if ( isArray ( promises ) ) {
43
- return new Promise ( ( resolve , reject ) => {
44
- let results = [ ] ;
45
- promises . reduce ( ( wait4 , promise ) => wait4 . then ( ( ) => promise . then ( val => results . push ( val ) ) ) , $q . when ( ) )
46
- . then ( ( ) => { resolve ( results ) ; } , reject ) ;
47
- } ) ;
43
+ return Promise . all ( promises ) ;
48
44
}
49
45
50
46
if ( isObject ( promises ) ) {
51
47
// Convert promises map to promises array.
52
48
// When each promise resolves, map it to a tuple { key: key, val: val }
53
49
let chain = Object . keys ( promises )
54
50
. map ( key => promises [ key ] . then ( val => ( { key, val} ) ) ) ;
51
+
55
52
// Then wait for all promises to resolve, and convert them back to an object
56
53
return $q . all ( chain ) . then ( values =>
57
54
values . reduce ( ( acc , tuple ) => { acc [ tuple . key ] = tuple . val ; return acc ; } , { } ) ) ;
You can’t perform that action at this time.
0 commit comments