Reputation: 5817
I have used StreamBuilder, StreamController, BehaviorSubject, Stream etc.. for some time now. But I am still confused about some definitions. Especially for this question, Is StreamController and BehaviorSubject a Stream in Dart?
The reason why I have this question is because I can find the following words/quotes online:
From the above 4 points from online doc, it gives me: BehaviorSubject is an Observable and then is a Stream. So BehaviorSubject is a Stream. And BehaviorSubject is a StreamController too. Thus StreamController is a Stream.
But if StreamController is a Stream, that will contradict with some other articles that Stream is actually a part of StreamController and you get the Stream from StreamController.stream.
If we talk about Sink, there will be even more confusing.
StreamController implements StreamSink. So a Sink is a special StreamController.
So from all of the above words, I kinda get the following result:
BehaviorSubject = StreamController = Observable = Stream = Sink
In the end, everything are the same thing... Am I crazy?
Edited: (I understand now. Hope it's correct)
To clarify my confusion, I think I have to understand "BehaviorSubject is a special StreamController"
this sentence.
By googling and checking some sdk code, I think I understand that BehaviorSubject is a special StreamController, but not vice versa. That will solve my confusion. BehaviorSubject extends Subject, and Subject implements StreamController. Thus "BehaviorSubject is a special StreamController"
is correct. But I can't say StreamController is a BehaviorSubject. Thus I can't say StreamController is a Stream even if BehaviorSubject is actually a Stream.
I hope what I understand above is correct.
Upvotes: 13
Views: 9812
Reputation: 495
Observable
class is deprecated in rxdart 0.23.1
Observable
can be replaced by Stream
Upvotes: 1
Reputation: 126904
A StreamController
is a StreamController
.
It does not extend anything. So it is not any of Observable
, Stream
, BehaviorSubject
or Sink
.
It does implement Sink
as you said and thus allow you to add data on it directly, i.e. use streamController.add
as well as streamController.sink.add
. This data is then passed onto the Stream
that each controller carries.
BehaviorSubject
is not actually part of the standard library and just a fancy addition to streams from rxdart
. It allows you to access the latest value at any time directly.
Upvotes: 11
Reputation: 47
Not crazy at all, A stream is just like a pipe that take in data as a sink and give it back as a stream, while StreamController is just use to control the the stream. i hope this is helpful
Upvotes: 4