RxJava Observable Timeout有时不工作

时间:2018-05-31 21:55:01

标签: java rx-java rx-java2

以下是我的代码段,有时Observable没有超时,

 Observable<A> AObservable = Observable.fromCallable(() ->
        //External Service Call
).timeout(800, TimeUnit.MILLISECONDS)
        .subscribeOn(Schedulers.io())
        .onErrorReturn(throwable -> {
            LOGGER.warn(format("Server did not respond within %s ms for id=%s", 800, id));
            return null;
        });

Observable<B> BObservable = Observable.fromCallable(() ->
        //External Service Call
).timeout(800, TimeUnit.MILLISECONDS)
        .subscribeOn(Schedulers.io())
        .onErrorReturn( throwable -> {
            LOGGER.warn(format("Service did not respond within %s ms for id=%s", 800, Id));
            return null;
        });

// Build Default response
Observable<C> CObservable = Observable.fromCallable(() ->
        // Build Default one
).subscribeOn(Schedulers.io());


return Observable.zip(AObservable, BObservable,CObservable,
        (AResponse, BResponse, CResponse) -> {

    // Handle response and combine them

}).toBlocking().first();

在我看来,有时如果服务超过800ms,则超时不会发生。我是否会错过任何属性,请告知。

0 个答案:

没有答案