O
O
Oleg9952018-11-26 16:40:22
Android
Oleg995, 2018-11-26 16:40:22

How to execute 2 requests sequentially in RxJava2?

There are 2 different services. The first one returns a list of cities, for the second request we pass the id of the city and get the weather.
The output is a list of cities with the weather for today.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2018-11-26
@zagayevskiy

On kotlin like this:

requestCityList()
    .switchMap { cityList -> 
        cityList.map { city -> requestWeather(city.id) }.combineLatest { it }
    }

In the Java version, Observable.combineLatest(Iterable, Function) is used similarly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question