- This tracker is for issues related to:
Dart core libraries ("dart:async")
- Dart SDK Version (
dart --version): Dart SDK version: 2.12.0-133.2.beta (beta) (Tue Dec 15 09:55:09 2020 +0100) on "macos_x64"
- Whether you are using Windows, MacOSX, or Linux (if applicable):
MacOSX
Reproduction Sample
import 'dart:async';
void main() async {
final bloc = Counter()..listen(print);
bloc.add(CounterEvent.increment);
}
enum CounterEvent { increment }
class Counter extends Bloc<CounterEvent, int> {
Counter() : super(0);
@override
Stream<int> mapEventToState(CounterEvent event) async* {
// Does not work
yield* _increment();
// Works
// yield state + 1;
// yield state + 1;
}
Stream<int> _increment() async* {
yield state + 1;
yield state + 1;
}
}
abstract class Bloc<E, S> {
Bloc(this._state) {
_eventController.stream.asyncExpand(mapEventToState).listen((s) {
_state = s;
_stateController.add(_state);
});
}
final _eventController = StreamController<E>();
final _stateController = StreamController<S>.broadcast();
S _state;
S get state => _state;
StreamSubscription<S> listen(void Function(S) onData) {
return _stateController.stream.listen(onData);
}
Stream<S> mapEventToState(E event);
void add(E event) => _eventController.add(event);
}
Reproduction Steps
- Run above sample observe output is:
- Comment line 16 and uncomment lines 19-20
@override
Stream<int> mapEventToState(CounterEvent event) async* {
// Does not work
// yield* _increment();
// Works
yield state + 1;
yield state + 1;
}
- Re-run and observe output is:
Expectations
I would expect that yielding inline would exhibit the same behavior as using yield* with a nested async generator.
Dart core libraries ("dart:async")dart --version):Dart SDK version: 2.12.0-133.2.beta (beta) (Tue Dec 15 09:55:09 2020 +0100) on "macos_x64"MacOSXReproduction Sample
Reproduction Steps
Expectations
I would expect that yielding inline would exhibit the same behavior as using
yield*with a nested async generator.