What's the difference between publish and multicast operator in rxjs 5?

谁说胖子不能爱 提交于 2019-12-10 02:43:36

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!