Skip to content

Instantly share code, notes, and snippets.

@markocupic
Last active January 5, 2023 11:28
Show Gist options
  • Save markocupic/0f49df91b8968ef471b78865707a43d2 to your computer and use it in GitHub Desktop.
Save markocupic/0f49df91b8968ef471b78865707a43d2 to your computer and use it in GitHub Desktop.
Demo: auto invocated javascript async await stack with promises
(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