RxJS Subscriber unsubscribe vs. complete

前端 未结 2 1441
灰色年华
灰色年华 2021-01-08 01:11

I was reading through the RxJS docs and want to make sure I\'m understanding the difference between Subscriber.unsubscribe() and Subscriber.complete()

2条回答
  •  别那么骄傲
    2021-01-08 01:53

    From my experience with the API, the idea is that: you don't call the Observable, the Observable calls you. You are able to trigger things if you create a Subject and next/complete the Subject though.

    That's why you will see some examples that have a "private" Subject as a class member, but the publicly exposed item is an Observable. The expectation is that you will subscribe to the Observable and the top level class will dispatch values through the Subject with next() and error(). The only way to complete the Observable/Subject is to complete() the Subject.

    Additionally, Subscriber does not have an unsubscribe() method, a Subscription does.

提交回复
热议问题