Reputation: 734
I just started on ReactiveX and Retrofit, Consider following example retrofit example,
@GET
public Observable<ResponseType1> makeFirstCall();
@POST
public Observable<ResponseType2 makeSecondCallWithFirstResponse(@Body ResponseType1 input);
Is it a good idea to have observable within another action1? like below
makeFirstCalle().subscribe((responseType1) -> {
makeSecondCallWithFirstResponse(responseType1).subscribe("second action goes here")
});
Upvotes: 0
Views: 229
Reputation: 3083
Why not use concatMap or flatMap?
makeFirstCall().concatMap(responseType1 -> makeSecondCallWithFirstResponse(responseType1))
.subscribe(....)
You can keep chaining if you have additional api calls. For example
makeFirstCall().concatMap(responseType1 -> makeSecondCallWithFirstResponse(responseType1))
.concatMap(responseType2 -> makeThirdCallWithSecondResponse(responseType2))
.subscribe(....)
Upvotes: 2