This article was originally published at https://maximorlov.com/understanding-async-await/
Learning async/await can be daunting. It's something yo...
For further actions, you may consider blocking this person and/or reporting abuse
As a younger dev I read a lot of similar descriptions of async/await mechanics but didn’t fully understand, and it was never fully explained, what the value was. Why do I care? What does using this pattern give me, and how does THAT work?
You hint at the value by mentioning that await pauses execution of that particular function, which implies that the thread could go an execute other instructions during that time that the first function execution is paused, but as a younger dev I couldn’t intuit that implication. I wished I had someone offering a mental model for that aspect of asynchronous programming when I was younger.
Very nice detailed explanation of asynchronous JavaScript!
Thank you Rense!
Async/await is just a syntax sugar for Promise/then.
Your article clarifies that concept for me, thanks for sharing it with us!
Happy to hear it clarified this topic for you!
thank you very much that was helpful
Glad to hear you found it helpful!
Nice explanation 👏
Thanks Jessica!
The simple explanation from a master of JS guru.
That's flattering, thanks 😊. Glad you liked it!
Do I need to always use await when calling the function (to retrieve the value) or I can omit using await if I don't need to use the retrieved value. For example if I have 'guests' in my database and I have function like find() which returns all of my guests (which is promise). Do I need to use await in some other function if I just want to call the function (that retrieves the guests) but I don't need to use the value. I think I know the answer already due to the article but still would like to ask. Great article regardless, one of the best I have read on the subject.
Great question! If you're not using the value you don't have to use await. But beware, if the functions throws the error won't be caught in the catch-block. Also any code running after the async function cannot assume the function has completed successfully. Say you run
sendNotification()
in the backend and then respond to the client that the notification has been sent, well, you don't know that for sure :). Hope that makes sense!Yes, absolutely! Thank you very much.
what software you used to draw