Rx Java mergeDelayError无法按预期工作 [英] Rx Java mergeDelayError not working as expected

查看:106
本文介绍了Rx Java mergeDelayError无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RxAndroid中使用RxJava和Android应用程序。我正在使用 mergeDelayError 将两个复古网络调用合并为一个可处理的observable如果要么发出一个项目,如果有任何一个项目则出错。这不起作用,它只会在遇到错误时触发onError操作。现在为了测试这个我转移到一个非常简单的例子,当我有一个onError调用时,仍然不会调用successAction。请参阅下面的示例。

I'm using RxJava in and Android application with RxAndroid. I'm using mergeDelayError to combine two retro fit network calls into one observable which will process emitted items if either emits one and the error if either has one. This is not working and it is only firing off the onError action when either encounters an error. Now to test this I shifted to a very simple example and still the successAction is never called when I have an onError call. See example below.

Observable.mergeDelayError(
                Observable.error(new RuntimeException()),
                Observable.just("Hello")
            )
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .finallyDo(completeAction)
            .subscribe(successAction, errorAction);

只有在使用两个成功的observable时,才会调用成功操作。我是否遗漏了mergeDelayError应该如何工作的内容?

The success action will only be called if I use two success observables. Am I missing something with how mergeDelayError is supposed to work?

编辑:

我发现如果我删除 observeOn subscribeOn 一切都按预期工作。我需要指定线程和思想,这是使用Rx的重点。知道为什么指定那些调度程序会破坏这种行为吗?

I've found that if I remove the observeOn and subscribeOn everything works as expected. I need to specify threads and thought that was the whole point of using Rx. Any idea why specifying those Schedulers would break the behavior?

推荐答案

这个仍然看起来像mergeDelayError运算符中的一个错误,但我能够通过复制每个observable的observerOn和Subscribe on来使它工作。

This still seems like a bug in the mergeDelayError operator but I was able to get it working by duplicating the observerOn and Subscribe on for each observable.

Observable.mergeDelayError(
            Observable.error(new RuntimeException())
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribeOn(Schedulers.io()),
            Observable.just("Hello")
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribeOn(Schedulers.io())
        )
        .finallyDo(completeAction)
        .subscribe(successAction, errorAction);

这篇关于Rx Java mergeDelayError无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆