I'm using Babel and Webpack. If I forget to await
an async function, it can often go unnoticed. Once in a while, if I forgot the await
, an error occurs in the async function and I get an Unhandled promise rejection
. Then, I realize that I forgot the await
.
Is there a way to get a warning when I forget to add an await
?
The call to the async method starts an asynchronous task. However, because no Await operator is applied, the program continues without waiting for the task to complete. In most cases, that behavior isn't expected.
In this way, an async function without an await expression will run synchronously. If there is an await expression inside the function body, however, the async function will always complete asynchronously. Code after each await expression can be thought of as existing in a . then callback.
What if we forget the await keyword ? If you forget to use await while calling an async function, the function starts executing. This means that await is not required for executing the function. The async function will return a promise, which you can use later.
The await keyword before a promise makes JavaScript wait until that promise settles, and then: If it's an error, an exception is generated — same as if throw error were called at that very place. Otherwise, it returns the result.
I think OP is looking for something like no-floating-promises
from tslint
see: https://palantir.github.io/tslint/rules/no-floating-promises/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With