.first and .firstWhere Futures don't return until two items are added to a Stream by yield in an async* function #35063
Labels
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
closed-duplicate
Closed in favor of an existing report
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
dart --version
): 2.0.0 and 2.1.0-dev.5.0.flutter-a2eb050044I have a Stream (or technically a _ControllerStream) that is constructed using async*, await for, and yield. It works the way I would expect until I try to use .first or .firstWhere to get the first item from that Stream, at which point I see surprising behavior -- the first item is eventually returned by the .first Future, but only after a second item has been yielded by the async* function that generates the Stream. Even more surprisingly, when using .firstWhere, the boolean test function is evaluated after the first item has been yielded, but the Future still doesn't return until the second item is yielded.
Below is example code and it's output, where you can see an async listener in getFirstOverAndOver that does not receive the first value until after two items are added to the source stream and two items yielded by the async* streamFromStreamViaAsyncStar, even though the second item is not yielded until a full second after the first event was yielded. The final value of 4 is only received ~ 15 seconds after it is yielded, when the source StreamController is closed.
Output of the code:
The text was updated successfully, but these errors were encountered: