Closed
Description
discarded_futures
Description
Don't discard futures in async functions.
Details
Making asynchronous calls in non-async
functions is usually the sign of a programming error. In general these functions should be marked async
and such futures should likely be awaited (as enforced by unawaited_futures
).
In case you really do want to discard a Future in a non-async
function, the recommended way is to use unawaited
from dart:async
. The // ignore
and // ignore_for_file
comments also work.
Kind
Error
Good Examples
Future<void> recreateDir(String path) async {
await deleteDir(path);
await createDir(path);
}
Future<void> deleteDir(String path) async {}
Future<void> createDir(String path) async {}
Bad Examples
void recreateDir(String path) {
deleteDir(path);
createDir(path);
}
Future<void> deleteDir(String path) async {}
Future<void> createDir(String path) async {}
Discussion
See #57653, #58512 and unawaited_futures
.
/fyi @eernstg @diegovar @dowski @bsutton
Discussion checklist
- List any existing rules this proposal modifies, complements, overlaps or conflicts with.
- List any relevant issues (reported here, the SDK Tracker, or elsewhere).
- If there's any prior art (e.g., in other linters), please add references here.
- If this proposal corresponds to Effective Dart or Flutter Style Guide advice, please call it out. (If there isn’t any corresponding advice, should there be?)
- If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.