Chaining method calls using RxJava

你说的曾经没有我的故事 提交于 2020-03-05 07:51:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!