Await is only valid in async function #184
Answered
by
pinage404
Wamzel
asked this question in
WTF Questions
-
Beta Was this translation helpful? Give feedback.
Answered by
pinage404
Nov 27, 2020
Replies: 2 comments
-
There is two cases to use
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
If you care about the result of the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
denysdovhan
-
This is more like a question. A top-level |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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