Last active
March 3, 2020 10:41
-
-
Save leolanese/556cdbce7c04050b85368a37c44e1aa1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// - 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