我需要約5個鏈接請求例如我有5個不同的調用,我想讓他們串行不按特定順序並行。鏈接請求與改造和rxjava
這裏是我的觀測
Observable<ResponseBody> textsCall=EndpointFactory.provideEndpoint().getTexts(textsTask.getLanguage())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
Observable<AirportCombo> routesCall=EndpointFactory.provideEndpoint().getRoutes()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
的一些例子其實,我不知道是什麼功能做它的Java RX。
早先我實現了並行請求,現在我需要串行。
如果您在此處需要並行方法你:
Observable<ResponseResult> combined = Observable.zip(textsCall, routesCall, (textsBody, airportCombo) -> {
//some parsing and other logic
return new ResponseResult(flag);
});
通常會使用'flatMap()'來鏈請求這樣的..特別是在打第二個電話時需要第一個電話的結果。 –