const one = () => {
return new Promise((resolve) => {
setTimeout(() => resolve(2), 2000);
})
};
const two = () => {
return new Promise((resolve, reject) => {
setTimeout(() => reject(3), 3000);
})
};
const three = () => {
return new Promise((resolve) => {
setTimeout(() => resolve(5), 5000);
})
};
const arr = () => {
return [one(), two(), three()];
}
// This is only needed in NodeJS
(async () => {
try {
for await (const result of arr()) {
console.log('result:', result)
}
} catch (e) {
console.log('caught', e);
}
})();