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

前端 未结 4 1377
梦谈多话
梦谈多话 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:18

    Paul's answer pretty much nails it. There's a few things worth adding, though:

    AsyncSubject works as Paul says, but only after the source completes. Before that, it works like Subject (where "live" values are received by subscribers)

    AsyncSubject has changed since I last ran tests against it. It no longer acts as a live subject before completion, but waits for completion before it emits a value. And, as Sergey mentions, it returns the last value, not the first (though I should have caught that as that's always been the case)

    AsyncSubject is used by Prune, FromAsyncPattern, ToAsync and probably a few others

    BehaviorSubject is used by overloads of Publish that accept an initial value

    ReplaySubject is used by Replay

    NOTE: All operator references above refer to the publishing set of operators as they were before they were replaced with generalised publish operators in rev 2838 (Christmas '10) as it has been mentioned that the original operators will be re-added

提交回复
热议问题