Emit cached data in a later microtask

This commit is contained in:
Simon Binder 2019-07-11 21:07:22 +02:00
parent 0e7ee6114b
commit 256b91f03f
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
1 changed files with 6 additions and 1 deletions

View File

@ -23,7 +23,12 @@ class StartWithValueTransformer<T> extends StreamTransformerBase<T, T> {
..onListen = () {
final data = _value();
if (data != null) {
controller.add(data);
// Dart's stream contract specifies that listeners are only notified
// after the .listen() code completes. So, we add the initial data in
// a later microtask.
scheduleMicrotask(() {
controller.add(data);
});
}
subscription = stream.listen(