请找到下面的kotlin代码段:
val dummyApi: PublishSubject<String> = PublishSubject.create()
fun withLatestFromtest() {
dummyApi.onNext("1")
getOtherObservable().withLatestFrom(dummyApi)
.subscribeOn(Schedulers.io())
.subscribeBy(
onNext = {
Log.e("TAG", "Pair ${it.first} /// ${it.second}")
},
onError = {
it.printStackTrace()
},
onComplete = {
Log.e("TAG", "Pair2 Complete")
}
)
dummyApi.onNext("2")
dummyApi.onNext("3")
}
private fun getOtherObservable(): Observable<String>{
return Observable.just("API")
.delay(2, TimeUnit.SECONDS)
}
预期输出-
Pair API /// 3
Pair2 Complete
实际输出-
Pair2 Complete
当我删除 .subscribeOn(Schedulers.io())时,它可以正常工作。我不明白为什么调度程序会造成此问题。