Last active
January 5, 2023 11:28
-
-
Save markocupic/0f49df91b8968ef471b78865707a43d2 to your computer and use it in GitHub Desktop.
Demo: auto invocated javascript async await stack with promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
await (() => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('first'); | |
resolve('first'); | |
}, 5000); | |
}); | |
})(); | |
await (() => { | |
return new Promise((resolve, reject) => { | |
console.log('second'); | |
resolve('second'); | |
}); | |
})(); | |
await (() => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
console.log('third'); | |
resolve('third'); | |
}, 1000); | |
}); | |
})(); | |
})(); | |
// Will output | |
// first | |
// second | |
// third |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment