I have been reading up on async/await in Node.js. I have learnt that the await
keyword waits for a promise to be resolved, or throws an exception if it was rejected.
I have also learnt that every function that wants to use await
needs to be marked async
. However, what does it mean for a function to be marked async?
All the resources and blog posts I was able to find seem to explain await
in great detail, but ignore the concept of an async
function, or briefly gloss over it. For instance, this author puts it like this:
This makes the function return a Promise implicitly.
What does the async
keyword really do? What does it mean for a function to implicitly return a Promise? What are the side effects other than being able to use await
?
Alright, so from the answers I have received so far it's clear that it simply wraps the function's return value into a Promise
, much like Promise.then
would. That just leaves a new question though. Why does a function that uses await
need to be async
and thus return a Promise
?