CodyC
CodyC3y ago

Lint for if you forgot to `await` a Promise?

If you have async methods that you call for their side effects, it's easy to forget to await them. Is there a lint rule that I can enable for that? (Sort of like Rust's rules about unused Results?) ex:
async myFn() {
// code

// oops, I forgot to await:
doThing()

// more code
// fails at runtime because doThing()
// hasn't finished yet.

}
async myFn() {
// code

// oops, I forgot to await:
doThing()

// more code
// fails at runtime because doThing()
// hasn't finished yet.

}
3 Replies
CodyC
CodyCOP3y ago
I've been searching/skimming https://lint.deno.land/ but don't see a relevant one yet.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
CodyC
CodyCOP3y ago
Yeah, I knew about require-await, and it's enabled by default. (Which TBH I find a bit annoying. :p) Yeah, I know there are some times where you don't want to await the promise. But if you enable the lint, you could handle that by just creating a function like
function noAwait<T>(p: Promise<T>): void {}
function noAwait<T>(p: Promise<T>): void {}
To explicitly mark cases you don't want to wait for. (which is almost never in my admittedly limited experience)

Did you find this page helpful?