I want to combine asynchronous functions that i need to await and functions I don't need to await. First the code...
async function doSomeStuff() {
try {
const data = await getDataFromDatabase()
if(data.canDoStuff == "yes") {
doAsynchronousStuffIDoNotNeedToAwait()
}
if(data.canDoSecondStuff == "yes") {
doSecondAsynchronousStuffIDoNotNeedToAwait()
.then(result => console.log("Done!");
}
} catch(err) {
console.log(err)
}
}
Here is my questions. If my doAsynchronousStuffIDoNotNeedToAwait()
throws an error, does it trigger the catch function? In second function doSecondAsynchronousStuffIDoNotNeedToAwait()
is there a better way of handling the result? Does this code have some downsides or can it be written better way?
I hope that questions are clear and code is simple enough to understand. If not please leave comment and I will edit my question. Thank you :)