Fallback Observable for RxJava

前端 未结 6 1429
-上瘾入骨i
-上瘾入骨i 2021-02-02 00:25

I\'m in search for a better way to achieve a simple Observable fallback system for empty results when using RxJava. The idea is that, if a local query for a set of data results

6条回答
  •  无人及你
    2021-02-02 01:14

    You can concatenate your Observables as well:

    Observable o1 = Observable.empty();
    Observable o2 = Observable.empty();
    Observable o3 = Observable.just(3);
    Observable o4 = Observable.just(4);
    Observable os = Observable.concat(o1, o2, o3, o4);
    Integer v = os.toBlocking().first();  // returns 3
    

提交回复
热议问题