DEV Community

Lem Dulfo
Lem Dulfo

Posted on

IDE Warning When Calling Async Function with No Await

When should it be okay to not have an await for an async call?
Sometimes, I just want to call the async function, but not have to wait for its result. You might want your code to keep going, without needing the return value:

Image description

Thing is, the IDE will show a warning. It also signals to other devs in your team that "something may or may not be needed to be done for this warning". The worst that could happen is someone else tries to "fix" this by adding an await, and it slows down your app.

But if you're sure you're not waiting for the result and you want to signal to the IDE and your team that it's okay, here's what you can do.

Image description

Receive the result in _, which is generally accepted as a prefix for unused variables.

This way the IDE knows that you're aware that something is being returned, in this case it's a Promise, and that you're okay with not doing anything with the result.

This also keeps the visual tidy, while telling your teammates the intent. They won't be adding an unwanted await.

Top comments (2)

Collapse
 
boly38 profile image
Brice

do someone know how to activate this lint warn on IntelliJ IDE ? I want it but it seems not possible from editor inspection options ..

Collapse
 
bytehala profile image
Lem Dulfo

Settings > Inspections > Javascript and Typescript > Async code and promises > Missing await for an async function call

Screenshot showing where to find missing async warning in Intellij