ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.36k stars 272 forks source link

.shareValue() does not provide up-to-date .value #719

Closed mrRedSun closed 1 year ago

mrRedSun commented 1 year ago
  final subject = BehaviorSubject<int>();
  final doublesValueStream = subject.map((v) => v * 2).shareValueSeeded(10);
  await Future.delayed(const Duration(milliseconds: 100));
  subject.add(100);
  await Future.delayed(const Duration(milliseconds: 100));
  print(doublesValueStream.value);

From seeing the implementation of shareValue I assume it should listen to the source stream and provide value via the underlying subject. However, the above example results in 10 being printed instead of 200. Is there a way to achieve this result where the resulting ValueStream would contain up-to-date value?

As expected

  final subject = BehaviorSubject<int>();
  final doublesValueStream = subject.map((v) => v * 2).shareValueSeeded(10)..listen((event) {});

  await Future.delayed(const Duration(milliseconds: 100));
  subject.add(100);
  await Future.delayed(const Duration(milliseconds: 100));

  print(doublesValueStream.value);

Works as expected. If this is a bug I am willing to look into the fix during the weekend, but need confirmation if this is a bug or expected behavior

rxdart: ^0.27.7 is used

hoc081098 commented 1 year ago

That is expected behavior

mrRedSun commented 1 year ago

Roger, gonna close this then, thanks