These are chat archives for ReactiveX/RxJava

23rd
Jun 2016
James
@jemmrich
Jun 23 2016 15:57
I have services which return observables (like http services), the services accept params for the http call, how can I use Zip to execute multiple observables which require params that depend on the previous observables response? Is that possible or do I just have to nest subscribes within subscribes within subscribes?
Dorus
@Dorus
Jun 23 2016 15:57
you can zip as long as all sources emit the same number of values
pretty common pattern
Ben Christensen
@benjchristensen
Jun 23 2016 15:58
Don't nest subscribes. That's an anti-pattern
Dorus
@Dorus
Jun 23 2016 15:59
Bit old, but for example it's used here: http://techblog.netflix.com/2013/02/rxjava-netflix-api.html (the zip trick, not nesting subscribers)
there is also a nice precentation but i cant find it quickly.
Ben Christensen
@benjchristensen
Jun 23 2016 15:59
It causes grief with error handling, backpressure, etc
Yes, that example is good. Here is code as well related to that blog and similar presentations: https://github.com/Netflix/ReactiveLab/blob/master/reactive-lab-gateway/src/main/java/io/reactivex/lab/gateway/routes/RouteForDeviceHome.java
James
@jemmrich
Jun 23 2016 16:00
I just have a couple (not a lot) of apis that I need to call sequentially and for now I am having to nest the subscribes which is something that makes me cringe. But the apis I need to call supply data that the next api needs for its call
Ben Christensen
@benjchristensen
Jun 23 2016 16:01
Use flatMap in almost all cases where nested subscribes occur.
James
@jemmrich
Jun 23 2016 16:01
@Dorus Thanks I am going to read that link you provided
Ben Christensen
@benjchristensen
Jun 23 2016 16:01
It is almost never needed or a good idea to
nest subscribes.
James
@jemmrich
Jun 23 2016 16:02
@benjchristensen absolutely agree
Ben Christensen
@benjchristensen
Jun 23 2016 16:02
FlatMap allows you to get the data from a previous call.
Hi :-)
James
@jemmrich
Jun 23 2016 16:04
@benjchristensen Ill have to look for some examples on flatmap, I saw it mentioned a few times, but didn't see or notice how to retrieve the results from the previous observable
@Dorus Thanks going to have a look at it
Ben Christensen
@benjchristensen
Jun 23 2016 16:07
The link I gave before shows how to use it. It's the most used operator for composition.
stream.flatmap(value -> return something(value.arg))
James
@jemmrich
Jun 23 2016 16:11
@benjchristensen Thanks, you all have been very helpful