我在应用程序中使用了Retrofit和Coroutines。
所以我的应用程序中有两个不同的请求。我想将它们与coroutine's combine结合使用。
如果我想将两个请求彼此合并,则需要将它们设为Flow
。但是,当我定义对Flow的API请求时,会收到错误消息:
@GET("my_url")
fun getHomeDataFlow(@Header("Authorization") token: String): Flow<Pagination<Home>>
错误:
java.lang.IllegalArgumentException: Unable to create call adapter for kotlinx.coroutines.flow.Flow<codenevisha.ir.app.journey.data.model.response.Pagination<codenevisha.ir.app.journey.data.model.response.Home>>
for method APIService.getHomeDataFlow
这也是我的请求实现:
val homeFlow = oldRepository.getHomeDataFlow(params)
val categoryFlow = oldRepository.getCategoriesFlow()
var result = Pagination<Home>()
homeFlow.combine(categoryFlow) { receivedHome, receivedCategory ->
val home = Home()
home.setCategory(receivedCategory)
home.showType = Home.ShowType.CATEGORY.id
receivedHome.results?.add(1, home)
receivedHome
}.collect {
result = it
}