Rxdart: BehaviorSubject disregards Exception and gives back last valid value when listend to. Intended?

Created on 27 Dec 2018  路  5Comments  路  Source: ReactiveX/rxdart

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:

  • Output 1: valid event.
  • Output 2: valid event.
  • Output 3: Exception.

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.

Most helpful comment

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 ;)

All 5 comments

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.

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 ;)

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.

Fixed in master, soon on pub

Thank you very much! :)

Was this page helpful?
0 / 5 - 0 ratings