Issue
I'm writing a simple test that is equivalent to:
Test fun testObservable() {
val returnedObservable = Observable.create(object : Observable.OnSubscribe<String> {
override fun call(t: Subscriber<in String>) {
t.onNext("hello")
t.onCompleted()
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
val result = returnedObservable.toBlocking().first()
assertEquals("hello", result)
}
The test blocks indefinitely on returnedObservable.toBlocking().first()
when .observeOn(AndroidSchedulers.mainThread())
is present.
Is there a way to transform the observable to return the result?
The returnedObservable
is returned from method call with .subscribeOn and .observeOn already applied so removing those is not an option.
Solution
I guess it is a bug mentioned here: https://github.com/ReactiveX/RxAndroid/issues/50
btw why don't you use RxKotlin?
You example will look much better:
val returnedObservable = observable<String> { subscriber ->
subscriber.onNext("hello")
subscriber.onCompleted()
}
.subscribeOn(Schedules.io())
.observeOn(AndroidSchedulers.mainThread())
Answered By - Sergey Mashkov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.