问题
Given two methods, both which returns a Single, what is the correct way, using Rx, to chain the two method calls together so that one method is called first, and the second once, and only if, the first completes successfully.
Ideally, the second method will be able to access the value returned by the first.
回答1:
Assuming your methods are like this:
static Single<String> method1() {
return Single.just("x");
}
static Single<String> method2(String in) {
return Single.just(in+"y");
}
the chaining will simply be:
Single<String> result = method1().flatMap(v -> method2(v));
来源:https://stackoverflow.com/questions/51879920/chaining-method-calls-using-rxjava