本文介绍了调试停止的RxJava zip运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用Java编写,我调用zip()方法,该方法接收一些返回Observable的方法.

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.

推荐答案

假设您拥有:

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

只需在每个来源上添加一个.doOnNext()即可记录其发出的内容(或订阅doOnNext而不是doOnNext).例如:

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...*/))

可能发生的情况是,这些光源之一发射的频率与其他光源发射的频率不同.当您严格知道所有信号源以相同的速度/频率发出事件时,必须使用zip.您可能想尝试使用combineLatest.两者之间的区别是:

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:仅当源的所有第n个项目均已发出时,返回的Observable才会发出第n个组合"项目.请参见关系图.
  • combineLatest:返回的Observable每当其任何源发出一个项目时,都会发出一个组合"项目.请参见关系图.
  • 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.

这篇关于调试停止的RxJava zip运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 00:48