gpt4 book ai didi

android - LiveData 到 Observable 转换使用 RxJava

转载 作者:行者123 更新时间:2023-11-29 14:16:36 25 4
gpt4 key购买 nike

通过使用 LiveDataReactiveStreams,可以将 LiveData 转换为 Publisher。但是为了使用 RxJava2 方法,例如 withLatestFrom,我需要有一个 Observable 而不是 Publisher。除了使用这个(过时的)库之外,还有其他方法可以将 Publisher 转换为 Observable - RxJava<->ReactiveStreams

最佳答案

// Flowable to LiveData

val flowable = Flowable.just(1, 2, 3)
val liveData = LiveDataReactiveStreams.fromPublisher<Int>(flowable)

// From Live Data to Publisher(Flowable is also publisher)

LiveDataReactiveStreams.toPublisher(this, liveData).subscribe(object: Subscriber<Int>{
override fun onNext(t: Int?) {}

override fun onComplete() {}

override fun onSubscribe(s: Subscription?) {}

override fun onError(t: Throwable?) {}
})

关于android - LiveData 到 Observable 转换使用 RxJava,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49974275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com