1var p1 = Promise.resolve(3);
2var p2 = 1337;
3var p3 = new Promise((resolve, reject) => {
4 setTimeout(resolve, 100, "foo");
5});
6
7Promise.all([p1, p2, p3]).then(values => {
8 console.log(values); // [3, 1337, "foo"]
9});
1Promise.all([Promise1, Promise2, Promise3])
2 .then(result) => {
3 console.log(result)
4 })
5 .catch(error => console.log(`Error in promises ${error}`))
1const promise1 = Promise.resolve(3);
2const promise2 = 42;
3const promise3 = new Promise(function(resolve, reject) {
4 setTimeout(resolve, 100, 'foo');
5});
6
7Promise.all([promise1, promise2, promise3]).then(function(values) {
8 console.log(values);
9});
10// expected output: Array [3, 42, "foo"]
11
1var arr = [
2 {subarr: [1,2,3]},
3 {subarr: [4,5,6]},
4 {subarr: [7,8,9]}
5];
6function processAsync(n) {
7 return new Promise(function(resolve) {
8 setTimeout(
9 function() { resolve(n * n); },
10 Math.random() * 1e3
11 );
12 });
13}
14Promise.all(arr.map(function(entity){
15 return Promise.all(entity.subarr.map(function(item){
16 return processAsync(item);
17 }));
18})).then(function(data) {
19 console.log(data);
20});