Created
March 29, 2021 14:31
-
-
Save strboul/6c6f35df5fa96a6ee33e95d2a732af9c to your computer and use it in GitHub Desktop.
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
const sleep = (ms) => { | |
return new Promise((resolve) => { | |
setTimeout(resolve, ms); | |
}); | |
}; | |
const queryDb = async (success) => { | |
await sleep(3000); | |
if (!success) { | |
throw new TypeError(); | |
} | |
console.log("database queried"); | |
}; | |
const init = async () => { | |
console.log("before"); | |
await queryDb(true); | |
console.log("after"); | |
console.log("before 2"); | |
await queryDb(false); | |
console.log("after 2"); | |
}; | |
init(); | |
// before | |
// database queried | |
// after | |
// before 2 | |
// /home/myazici/async.js:10 | |
// throw new TypeError(); | |
// ^ | |
// | |
// TypeError | |
// at queryDb (/home/myazici/async.js:10:11) | |
// at async init (/home/myazici/async.js:21:3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment