Skip to content

Files

Latest commit

 

History

History
36 lines (25 loc) · 875 Bytes

unawaited_futures.md

File metadata and controls

36 lines (25 loc) · 875 Bytes

Pattern: Unawaited Future

Issue: -

Description

DO await functions that return a Future inside of an async function body.

It's easy to forget await in async methods as naming conventions usually don't tell us if a method is sync or async (except for some in dart:io).

When you really do want to start a fire-and-forget Future, the recommended way is to use unawaited from package:pedantic. The // ignore and // ignore_for_file comments also work.

Example of correct code:

Future doSomething() => ...;

void main() async {
 await doSomething();

 unawaited(doSomething()); // Explicitly-ignored fire-and-forget.
}

Example of incorrect code:

void main() async {
 doSomething(); // Likely a bug.
}

Further Reading