Promise.all中的动态数组

时间:2018-04-12 13:14:39

标签: javascript node.js es6-promise

如果在Promise.all之后向数组添加promise - 它将被忽略

let pr = [];
let start = Date.now();

pr.push(new Promise((resolve) => {
    setTimeout(() => {
        resolve();
    }, 2000);
}));

Promise.all(pr).then(() => {
    console.log('All done' + (Date.now() - start));
});

pr.push(new Promise((resolve) => {
    setTimeout(() => {
        resolve();
    }, 4000);
}));
  

所有done2000

我该怎么做?

0 个答案:

没有答案