Debugging RxJava zip operator that halts

大兔子大兔子 提交于 2019-12-12 13:19:29

问题


Writing in Java I call zip() method that receives a few method that return an Observable<...>.

Currently I am not able to progress to the following map and this is probably due to the fact that one of the methods didn't return a value yet. (Though it seems all methods where called.)

Is there a way to debug the process and see why it is stuck?
Thanks.


回答1:


Suppose you have:

result = Observable.zip(sourceA, sourceB, sourceC)

Just add a .doOnNext() on each of the sources to log what they are emitting (or instead of doOnNext, subscribe to each). For instance:

result = Observable.zip(sourceA.doOnNext(/*logging...*/),
                        sourceB.doOnNext(/*logging...*/),
                        sourceC.doOnNext(/*logging...*/))

What's probably happening is that one of these sources isn't emitting at the same frequency as the others. zip must be used when you strictly know that all the sources emit events at the same pace/frequency. You might want to try using combineLatest. The difference between the two are:

  • zip: the returned Observable emits the n-th 'combination' item only when all the n-th items of the sources have been emitted. See a diagram.
  • combineLatest: the returned Observable emits an 'combination' item whenever any of its sources emits an item. See a diagram.


来源:https://stackoverflow.com/questions/25862198/debugging-rxjava-zip-operator-that-halts

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