Description
This could be part of void_checks or unawaited_futures.
Given, the following function which takes a void function:
void foo(void Function() bar) {
...
}
and the following call site:
foo(() async {
...
});
We can confidently say that the resulting future will never be awaited. We can also say, this is a value that probably shouldn't be thrown away into a void location.
There's therefore an argument that this should be flagged by either void_checks or unawaited_futures.
It applies to other cases too:
final List<void> voidList = <Future>[...];
// or even what about.. ?
final List<Object> objectList = <Future>[...];
though these probably don't have to be covered right away.
As an argument against this, I expect the following type of code to be common:
stream.listen((x) async {
...
});
in the case where (x) async {...}
needs to do async work, there's no better way to write this.
And yes it may have race conditions, but if the code needs synchronization, it looks wrong to me for it to not have synchronization explicitly:
stream.listen((x) async {
await lock.aquire();
...
lock.release();
});
But the lint may still catch cases where a the misuse an API, and hopefully there's a correct way to use the API that they can find after they see the lint.
[...].forEach((x) async {
// this won't be awaited! What if these need to execute serially?
....
});
// there's no forEachAsync, however, there are other ways of doing what you want:
await [...].fold(Future<void>.value(null), (future, next) async {
await future;
....
});
Counterpoint: the lack of await forEach()
tells you that the code won't be serial, and so maybe that's another clue that this type of error isn't common.