Zip运算符严格将可发现的物品发送出去.它等待(或更多)项目到达,然后合并它们.所以是的,这将适合您的需要.
我将使用Func2链接前两个可观察的结果.
注意,如果您使用Retrofit,这种方法会更简单,因为它的api接口可能返回一个可观察的.否则,您将需要创建自己的可观察值.
// assuming each observable returns response in the form of String
Observable movOb = Observable.create(...);
// if you use Retrofit
Observable picOb = RetrofitApiManager.getService().uploadPic(...),
Observable.zip(movOb, picOb,
new Func2() {
@Override
public MyResult call(String movieUploadResponse,
String picUploadResponse) {
// analyze both responses, upload them to another server
// and return this method with a MyResult type
return myResult;
}
}
)
// continue chaining this observable with subscriber
// or use it for something else