Skip to content

Instantly share code, notes, and snippets.

@casschin
Created October 21, 2018 21:26
Show Gist options
  • Save casschin/a7f61a2a16141e9c0a2e7a1e1823e2f5 to your computer and use it in GitHub Desktop.
Save casschin/a7f61a2a16141e9c0a2e7a1e1823e2f5 to your computer and use it in GitHub Desktop.
Simple async/await example
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