Android – rxjava2 converts flowable to single

How to convert flowable to single? Or, if there is another way to make it stop emitting light after the first response of interest

I've tried this, but it doesn't seem to work:

  disposables.add(
        repository.getAllSomethings()
           .subscribeOn(SchedulerProvider.getInstance().computation())
           .observeOn(SchedulerProvider.getInstance().ui())
           .toSingle()
           .subscribeWith(object : DisposableSingleObserver<List<Something>>() {
                override fun onSuccess(t: List<Something>) {
                }

                override fun one rror(e: Throwable) {
                }
            })

Getallthings() returns a flowable < list < something > >

In the above code,. Subscribewith() is underlined in red:

Type parameter bound for E in 
fun <E : SingleObserver<in Flowable<List<Something>!>!>!> subscribeWith(observer: E!): E!
is not satisfied: inferred type  ! is not a subtype of SingleObserver<in Flowable<List<Something>!>!>!

resolvent:

OK, thanks @akarnokd, I saw the answer in the comments

Teach me how to fish instead of giving me a direct answer. He suggested looking here: http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Flowable.html (I really should do it the first time!)

There I found that firstorerror () solved my problem

Even if the single object I call is a flowable, the IDE doesn't complain. However, looking at the link above, tosingle () is not even an effective choice!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>