What is the difference between System.Reactive.Subjects.Subject<T> and System.Reactive.Subjects.ReplaySubject<T> classes?
One doesn't derive from another, but they have the same description and implement same interfaces in MSDN.
Take this code:
var subject = new Subject<int>();
subject.OnNext(42);
subject.OnCompleted();
subject.Subscribe(x => Console.WriteLine(x));
And compare to this:
var subject = new ReplaySubject<int>();
subject.OnNext(42);
subject.OnCompleted();
subject.Subscribe(x => Console.WriteLine(x));
The first produces no values. The second produces 42.
Basically Subject only produces values to current subscribers and ReplaySubject remembers values for future subscribes (when it "replays" the values).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With