问题
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