使用Rx
一个可以合并多个订阅源,如下所示
// psudo data repository
fun getAllData(): Flowable<DataType> {
return getCachedData().mergeWith(getRemoteData())
}
fun getCachedData(): Flowable<DataType> {
// local database call
}
fun getRemoteData(): Flowable<DataType> {
// network call
}
在上面的代码中,getAllData()
一旦合并Flowables
返回之一,将立即返回数据,然后在准备好后发送另一个。
问题是,如何使用 Kotlin 协程实现相同的结果produce
?