Promise.all even rejects

by amindunited

JavaScript

const wait10 = (index) => {
	return new Promise((resolve, reject) => {
    setTimeout(() => {
    	console.log('index: ', index);
    	resolve(index);
    }, 100);
  });
};

const fail10 = (index) => {
	return new Promise((resolve, reject) => {
    setTimeout(() => {
    	console.log('index: ', index);
    	reject(index);
    }, 100);
  });
};

const wait20 = (index) => {
	return new Promise((resolve, reject) => {
    setTimeout(() => {
    	console.log('index: ', index);
    	resolve(index);
    }, 200);
  });
};

const myPromises = [
	wait10(1),
  wait10(2),
  wait20(3),
	fail10(4),
  wait10(5),
  wait20(6),
  wait10(7)
].map((fn) => {
	return new Promise((resolve, reject) => {
    fn.finally(resolve);
  })
});

Promise.all(myPromises)
.finally(data => {
	console.log('Done!');
});