0

if add promise to array after Promise.all - it will be ignored

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);
}));

All done2000

How can i do it?

  • Of course it will be ignored, the promise doesn't exist yet. Why can't you simply move that in front of the `Promise.all` call? [Works just fine](https://stackoverflow.com/q/46830699/1048572). – Bergi Apr 12 '18 at 13:27
  • https://stackoverflow.com/a/37819138/1048572 – Bergi Apr 12 '18 at 13:30
  • Promise will be added while animation run Before animation i have't promise :c – Alexey Vodolazhchenko Apr 12 '18 at 13:38
  • You might want to show the code for your [actual problem](https://meta.stackexchange.com/q/66377) then. An animation should not add a promise to anything, it should make a promise for the whole thing at the start already. See also [Promises for promises that are yet to be created](https://stackoverflow.com/q/37426037/1048572) – Bergi Apr 12 '18 at 13:50
  • Thank you, i did it like this :) – Alexey Vodolazhchenko Apr 12 '18 at 14:16

0 Answers0