For the second case, a function that call a Promise must :
give a callback that will be executed after the Promise finished the asynchronous task
let the Promise do side-effect
return a Promise
If you care about the result of the Promise and want to wait before executing others instructions, that means that this function will wait for an asynchronous task, and be asynchronous as well, that why the async keyword is required
await
is syntax sugar aroundPromise
There is two cases to use
await
:For the first case, the specification is currently in progress and will come in the future
For the second case, a function that call a
Promise
must :callback
that will be executed after thePromise
finished the asynchronous taskPromise
do side-effectPromise
If you care about the result of the
Promise
and want to wait before executing others instructions, that means that this function will wait for an asynchronous task, and beasync
hronous as well, that why theasync
keyword is required