Here is an example. The console displays the order of such
1.1 1.2 -завершились- 3.1 3.2 And you need to
-to complete-
displayed at the end. The function Promise.all, I understand, launches promises.
And how to hang up waiting, so that only when all promises are fulfilled does it work?
https://jsfiddle.net/aefuqvkL/
var promises = []; var pr = new Promise(function(resolve, reject) { console.log('1.1'); resolve(true); }); var pr2 = new Promise(function(resolve, reject) { console.log('1.2'); resolve(true); }); promises.push(pr); promises.push(pr2); Promise.all(promises).then(values => { console.log('-завершились-'); }); setTimeout(function() { pr.then(function() { console.log('3.1'); }, function() { console.log('4.1'); }); }, 1000); setTimeout(function() { pr2.then(function() { console.log('3.2'); }, function() { console.log('4.2'); }); }, 3000);
thenfunction returns a new Promise - Grundy