ReactiveX / rxdart

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

BehaviorSubject disregards Exception and gives back last valid value when listend to. Intended? #227

Closed Jonas-Sander closed 5 years ago

Jonas-Sander commented 5 years ago

In my flutter application I have a bloc. It not only sends data with a BehaviorSubject, but also exceptions (per stream.addError()), which I want to handle in the "front-end" by showing certain error messages to the user.

Let's say this is the bloc output:

Now if I listen to the Stream after Output 3 was added then I will only receive Output 2 and know nothing about Output 3 (the Exception). In the case of my app Output 2 would reflect an old state and might confuse users.

My way of thinking was that the BehaviorSubject would emit the last Output to any new listener disregarding if it is a "normal" value or an Exception. So in this example Output 3 instead of Output 2.

Is this intended? If yes I think it should be stated in the documentation.

Jonas-Sander commented 5 years ago

I tried solving it with a different BehaviorSubject emitting Exceptions and having 2 StreamBuilder, first checking the Exception stream. This is obviously not a really nice solution.

frankpepermans commented 5 years ago

Ah, our BehaviorSubject does what a regular broadcast stream does in this case,

That doesn't mean we can't implement this though. Seems that with Flutter, a lot of people do prefer the rx way over the Dart way, which is an on going struggle ;)

Jonas-Sander commented 5 years ago

Would be pretty nice!

I'm just asking myself if I'm doing something fundamentally wrong, as this is something I guess many people would face when using the bloc-pattern. But I don't know any other "clean" way I could handle this.

frankpepermans commented 5 years ago

Fixed in master, soon on pub

Jonas-Sander commented 5 years ago

Thank you very much! :)