I think that case 2 and 3 should produce the same output but it seams like yield* doesn't get along with broadcast streams and it needs to break the event loop to work properly.
As mentioned in this issue (via Stack Overflow), it's understandable that Dart may need to run another event loop to effectively listen to the stream.
The problem I see here is that listen does not return a Future , witch would make clear that this is an expected behavior. In a purely synchronous codebase, it should be semantically guaranteed by the language that we don't need to concern ourselves with event loops, especially when it is not explicitly pointed out in its documentation.
listen
function has different behaviors depending on how the stream is accessed.Case 1
Output is
1 2 3 4 5 6
Case 2
Delegating the stream in an
async*
functionOutput is
0 4 5 6
Case 3
Creating another stream controller
Output is
0 1 2 3 4 5 6
Thoughts
I think that case 2 and 3 should produce the same output but it seams like
yield*
doesn't get along with broadcast streams and it needs to break the event loop to work properly.As mentioned in this issue (via Stack Overflow), it's understandable that Dart may need to run another event loop to effectively listen to the stream.
The problem I see here is that
listen
does not return aFuture
, witch would make clear that this is an expected behavior. In a purely synchronous codebase, it should be semantically guaranteed by the language that we don't need to concern ourselves with event loops, especially when it is not explicitly pointed out in its documentation.