await for (final _ in stream)
for Stream<void>
results in build error
#48347
Labels
area-front-end
Use area-front-end for front end / CFE / kernel format related issues.
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Dear Dart/Flutter community
I am currently trying to process a
PriorityQueue<Item>
(https://api.flutter.dev/flutter/package-collection_collection/PriorityQueue-class.html) asynchronously. In my implementation I first add a new workload item to the queue and an event is emitted to the stream of aStreamController<void>
to signal new queue item(s) are available.An asynchronous
await for
loop receives the event from the stream, then checks the queue and processes all its items one after another as a whole, before receiving and processing the next stream event.As a matter of convenience, I tried the following:
This code will result in a build error:
Error: This expression has type 'void' and can't be used.
It would be great to allow for such a pattern for
void
events. I am currently using aStream<Null>
to circumvent the build error (which is advised against by the linter).The use of
.listen()
does not seem to be an option: Each workload item would be immediately processed when emitted, without any prioritizing taking place anymore, and the added risk of race conditions (I am currently work with Bluetooth Low Energy communications).I hope this report finds you well and am looking forward to your response😁
Best regards
Markus
The text was updated successfully, but these errors were encountered: