Reputation: 28906
I've this code:
Stream<int> get fooStream async* {
barStream.listen((_) async* {
int baz = await getBaz();
yield baz; // Does not work
});
}
How can I return Stream<int>
from another stream?
Note: If I use map
to transform the stream, then I'll have to return Stream<Future<int>>
, but I want to return Stream<int>
. I also don't feel like using rxdart
pacakge for this tiny thing.
Upvotes: 0
Views: 1016
Reputation: 688
Use asyncMap
.
barStream.asyncMap((e) => getBaz())
Use await for
Stream<int> get fooStream async* {
await for (final item in barStream) {
yield await getBaz();
}
}
Upvotes: 3