简体   繁体   English

RxJava:在onComplete中可观察

[英]RxJava: Get observable in onComplete

I may be something very obvious here, but in the onComplete() method of an Observer, how do I get at which Observable has called onComplete? 我在这里可能很明显,但是在观察者的onComplete()方法中,如何获得Observable调用过onComplete的方法?

More detail, say you have the following: 更详细地说,您具有以下条件:

event.subscribe((e) -> {
},
(error) -> {
},
() -> {
// HERE - How do I tell what event source is completing?
}

'event' is an observable. “事件”是可以观察到的。 Every item emitted by the observable will go through the chain of operators. 可观察者发射的每个项目都将通过操作员链。 After an item went through the operators it will be redirected to the subscriber, which is happening in 'subscribe'. 项目通过运营商后,将被重定向到订户,这在“订阅”中发生。 Subscribe provides two overloades. 订阅提供两个重载。 One for each emission of the stream (event) and the second one for noticing that the 'event'-Observable (stream) has been finished. 一种是针对流(事件)的每次发射,另一种是用于通知“事件”-可观察(流)已完成。

Lets look at a List, which will be converted in an Observable. 让我们看一下一个List,它将被转换成Observable。 If you convert an Array to an Observable with: 如果使用以下方法将数组转换为Observable:

Observable<Integer> integerObservable = Observable.fromArray(1, 2, 3);

you will get called for each value 1, 2, 3 onNext in the subscription. 您将为订阅中的每个值1、2、3 onNext调用。 The observable will be "onComplete" after 3 has been pushed to onNext. 将3推到onNext后,可观察的将是“ onComplete”。 Just look at the implementation on gitHub, to see what is happening. 只需查看gitHub上的实现,看看发生了什么。

Back to your question: How do I tell what event source is completing? 回到您的问题:我如何知道什么事件源正在完成? It would be the Observable 'event', because you are subscribing to it. 这将是可观察的“事件”,因为您正在订阅它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM