function slowFunction(message) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("DONE: " + message);
}, 3000)
});
}
// All
Promise.all([slowFunction("Alice"), slowFunction("Bob"), slowFunction("Charlie")])
.then((res) => {
console.log(res);
});
// Sequential
slowFunction("Alice")
.then((res) => {
console.log(res);
return slowFunction("Bob");
})
.then((res) => {
console.log(res);
return slowFunction("Charlie");
}).then((res) => {
console.log(res);
});