I need to order the execution of my code as follows:
- Promise 1
- Wait for 1 to finish, then run Promises 2 and 3 simultaneously
- The final function should wait for Promises 2 and 3 to complete
I'm struggling to figure it out, and here is the code I have so far.
function getPromise1() {
return new Promise((resolve, reject) => {
// do something asynchronously
resolve('myResult');
});
}
function getPromise2() {
return new Promise((resolve, reject) => {
// do something asynchronously
resolve('myResult');
});
}
function getPromise3() {
return new Promise((resolve, reject) => {
// do something asynchronously
resolve('myResult');
});
}
getPromise1()
.then(() =>
Promise.all([getPromise2(), getPromise3()])
)
.then(() => console.log('Finished!'));