Alex Rivera | Logout

What do the various ISubject implementations do and when would they be used?

Asked 2011-01-24T21:18:12.613
26

I have a fairly good idea of what the Subject class does and when to use it, but I've just been looking through the language reference on msdn and see there are various other ISubject implementations such as:

  • AsyncSubject
  • BehaviorSubject
  • ReplaySubject

As the documentation is pretty thin on the ground, whats the point of each of these types and under what situations would you use them?

Edit
Report

1 Answer

5

In regards to AsyncSubject

This code:

        var s = new AsyncSubject<int>();
        s.OnNext(1);
        s.Subscribe(Console.WriteLine);
        s.OnNext(2);
        s.OnNext(3);
        s.OnCompleted();

prints a single value 3. And it prints same if subscription is moved to after completion. So it plays back not the first, but the last item, plays it after completion (until complete, it does not produce values), and it does not work like Subject before completion. See this Prune discussion for more info (AsyncSubject is basically the same as Prune)

answered 2011-02-15T02:16:34.207

Your Answer