promise all reject code example
Example 1: javascript promise all
var p1 = Promise.resolve(3);
var p2 = 1337;
var p3 = new Promise((resolve, reject) => {
setTimeout(resolve, 100, "foo");
});
Promise.all([p1, p2, p3]).then(values => {
console.log(values);
});
Example 2: promise all
Promise.all([Promise1, Promise2, Promise3])
.then(result) => {
console.log(result)
})
.catch(error => console.log(`Error in promises ${error}`))
Example 3: Promise.all
const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise(function(resolve, reject) {
setTimeout(resolve, 100, 'foo');
});
Promise.all([promise1, promise2, promise3]).then(function(values) {
console.log(values);
});
Example 4: promise all in promise all
var arr = [
{subarr: [1,2,3]},
{subarr: [4,5,6]},
{subarr: [7,8,9]}
];
function processAsync(n) {
return new Promise(function(resolve) {
setTimeout(
function() { resolve(n * n); },
Math.random() * 1e3
);
});
}
Promise.all(arr.map(function(entity){
return Promise.all(entity.subarr.map(function(item){
return processAsync(item);
}));
})).then(function(data) {
console.log(data);
});