RxJ在Observable中完成与取消订阅之间的区别? [英] RxJs difference between complete and unsubscribe in Observable?
问题描述
完成活动后,将取消订阅可观察"或不可观察"或任何其他区别.
after complete event will unsubscribe Observable or not or any other difference.
推荐答案
您完成Observable
,并取消订阅Subscription
.这是对两个不同对象的两种不同方法.您订阅了一个可观察对象,该对象返回一个Subscription
对象.
You complete an Observable
, and unsubscribe a Subscription
. These are two different methods on two different objects. You subscribe to an observable which returns a Subscription
object.
如果您想停止收听Observable
中的发射,请致电subscription.unsubscribe()
.
If you want to stop listening to emits from the Observable
you call subscription.unsubscribe()
.
如果要完成Observable
的任务,请致电observable.complete()
. (这仅在Subject
和扩展Subject
的那些文件上存在).完整的方法本身也将取消订阅任何可能的订阅.
If you want an Observable
to be done with his task, you call observable.complete()
. (this only exists on Subject
and those who extend Subject
). The complete method in itself will also unsubscribe any possible subscriptions.
当Observable向其观察者发出OnError或OnComplete通知时,这将终止订阅.观察者无需向以这种方式终止的,由Observable终止的订阅发出取消订阅通知.
When an Observable issues an OnError or OnComplete notification to its observers, this ends the subscription. Observers do not need to issue an Unsubscribe notification to end subscriptions that are ended by the Observable in this way.
这篇关于RxJ在Observable中完成与取消订阅之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!