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
?
require-await
lint be enough for your needs? It won't catch imported async functions defined elsewhere but it will catch some cases – Dunnerequire all async function calls to have an await before them
- I wouldn't recommend you require it, warning would be sufficient, because it is perfectly valid not to require to await anasync
function - in fact, at least one place in your code would have to call a function taggedasync
without usingawait
, because of the relationship betweenawait/async
keywords – Samsunawait
directly in front of it (if we build the array dynamically). I guess what I'm looking for is a way to requireawait
by default, but we can suppress the error explicitly. This way, it ensures that async functions calls withoutawait
were intentional. – Goodfornothing++
for ESLint, I'd say this is something that should be the task of your IDE. – Seventeenawait
ed because await is only valid inside async. So the first async function that gets called returns a promise that you must call.then()
on. Other async functions that that async function then call can be awaited. That's why JaromandaX says there MUST be at least one place in your code without await – Judges