问题
I'm reading the rxjs manual, I'm a little confused about what's the difference between multicast and publish operators. They seem very similar.
回答1:
I had the same question when reading http://reactivex.io/rxjs/manual/overview.html. So to make it clear, .publish()
is just shorthand for .multicast(new Rx.Subject())
(and publishBehavior
, publishLast
, and publishReplay
are similar but instantiate BehaviorSubject
, AsyncSubject
and ReplaySubject
respectively).
回答2:
They are indeed very similar, and they have a history that makes it even more confusing.
In simple terms, publish is a special case of multicast. publish always creates a new subject (and then pretty much uses multicast), whereas multicast uses the subject provided as an argument.
来源:https://stackoverflow.com/questions/38025123/whats-the-difference-between-publish-and-multicast-operator-in-rxjs-5