Created
October 21, 2018 21:26
-
-
Save casschin/a7f61a2a16141e9c0a2e7a1e1823e2f5 to your computer and use it in GitHub Desktop.
Simple async/await example
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
function logFirst() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(console.log("first")), 300); | |
}); | |
} | |
function logSecond() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(console.log("second")), 100); | |
}); | |
} | |
function logThird() { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(console.log("third")), 200); | |
}); | |
} | |
async function callLogs(isAwait) { | |
if (isAwait) { | |
await logFirst(); | |
await logSecond(); | |
await logThird(); | |
} else { | |
logFirst(); | |
logSecond(); | |
logThird(); | |
} | |
} | |
callLogs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment