How can PublishSubject and BehaviorSubject be unsubscribed from?

后端 未结 3 1717
[愿得一人]
[愿得一人] 2020-12-23 09:52

Under the subjects package you have classes like PublishSubject and BehaviorSubject which I suppose can be described as some usable sa

3条回答
  •  再見小時候
    2020-12-23 10:23

    All Subjects extend Observable which you can subscribe to using any of the multiple subscribe(...) methods. Call to any of the subscribe(...) methods returns a Subscription.

    Subscription subscription = anySubject.subscribe(...);
    

    Use this subscription instance's unsubscribe() method when you want to stop listening to the events from the Subject.

    subscription.unsubscribe();
    

提交回复
热议问题