Const a=(s)=& gt; {
The return of new Promise ((resolve, reject)=& gt; {
SetTimeout (
(a)=& gt; {
console.log(a);
},
S * 1000,
S
);
});
};
(async ()=& gt; {
Const times=[1, 2, 3, 4].
Await Promise. All (
Times. The map (async (time)=& gt; {
Await a (time);
Await a (time + 1.5);
})
). The catch ((e)=& gt; {
The console. The log (" promise all the error ", e);
});
}) ();
` ` `
Why only output the
1
2
3
4
Rather than
1
2
2.5
3
3.5
4
4.5
5.5
CodePudding user response:
Return in the first method a promise no resolve or reject, promise the pending status hasn't changed, so only output the four values;Second, even in here to add the resolve method a (a), while outputs eight values, but the order won't be said of 2 kinds of circumstances, should be the following order output
1
2
3
2.5
4
3.5
4.5
5.5