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

前端 未结 4 1360
梦谈多话
梦谈多话 2021-01-31 09:19

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 I

4条回答
  •  鱼传尺愫
    2021-01-31 10:20

    In regards to AsyncSubject

    This code:

            var s = new AsyncSubject();
            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)

提交回复
热议问题