Chain two retrofit observables w/ RxJava

前端 未结 2 1946
一向
一向 2020-12-25 12:27

I want to execute 2 network calls one after another. Both network calls return Observable. Second call uses data from successful result of the first call, method in successf

2条回答
  •  失恋的感觉
    2020-12-25 13:06

    In addition to Anthony R.'s answer, there is a flatMap overload which takes a Func2 and pairs your primary and flattened values for you. In addition, look at the onErrorXXX and onExceptionXXX operators for error manipulation, and chain them with your first and second Observables

    first.onErrorReturn(1)
    .flatMap(v -> service(v).onErrorReturn(2), (a, b) -> a + b);
    

提交回复
热议问题