所以我尝试用RxJava2 zip
实现并行请求
private fun getDetails(marketDataQuotes: MarketDataQuotes, instrumentById: InstrumentById, subscribe: Subscribe): Observable<DetailsWatchListModel> {
return Observable.zip(
getMarketDataQutoes(marketDataQuotes),
getInstrumentById(instrumentById),
getSubscribeInstrument(subscribe),
Function3<MarketDataQuotesResponse, List<InstrumentByIdResponse>, SubscribeResult,DetailsWatchListModel>
{ marketData, instrumentList, subscribeInstrument ->
detailWatchList(marketData, instrumentList, subscribeInstrument)
})
}
private fun getSubscribeInstrument(subscribe: Subscribe): LiveData<SubscribeResult> {
val mutableLiveData = MutableLiveData<SubscribeResult>()
remoteServices.requestSubscribe(subscribe)
.subscribeOn(Schedulers.io())
// .observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : ErrorCallBack<BaseResponse<SubscribeResult>>() {
override fun onSuccess(t: BaseResponse<SubscribeResult>) {
L.d("Success of Market data Quotes")
// mutableLiveData.value = transform(t)
}
})
return mutableLiveData
}
其他API调用与单一位置错误处理和基本响应结构
类似和服务一样
@Headers("Content-Type: application/json")
@POST("instruments/subscription")
fun requestSubscribe(@Body subscribe: Subscribe): Observable<BaseResponse<SubscribeResult>>
使用Kotlin v1.2.21,retofit 2.3.0,RxJava2 2.1.5请让我知道我做错了什么.. Tanx in Advance
答案 0 :(得分:0)
LiveData
无法使用RxJava压缩。
您需要使用此API:https://developer.android.com/reference/android/arch/lifecycle/LiveDataReactiveStreams.html
所以将LiveData转换为RxJava然后压缩它。