Skip to content

Instantly share code, notes, and snippets.

@leolanese
Last active March 3, 2020 10:41
Show Gist options
  • Save leolanese/556cdbce7c04050b85368a37c44e1aa1 to your computer and use it in GitHub Desktop.
Save leolanese/556cdbce7c04050b85368a37c44e1aa1 to your computer and use it in GitHub Desktop.
// - WAIT FOR ME! - I PROMISE.
// resolve NESTED promises waiting for inner promises
function nestedPromisesThatresolveAfter4Seconds() {
return new Promise(resolve => {
setTimeout(() => {
setTimeout(() => {
console.log('setTimeout1')
resolve('Promise resolved');
}, 4000);
console.log('setTimeout2')
}, 4000);
});
}
async function asyncCalltoPromise() {
console.log('calling Promise(s) but also WAITING FOR IT/THEM to get resolve.');
const result = await nestedPromisesThatresolveAfter4Seconds();
console.log(result);
}
asyncCalltoPromise();
// setTimeout2
// setTimeout1
// Promise resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment