I have an RxJava Completable
that I want to execute, then chain to a Single<Long>
. I can write it like this:
return Completable.complete().toSingleDefault(0L).flatMap { Single.just(1L) }
but this seems unnecessarily complicated. I would have thought Completable#toSingle()
would do the job, but if I write:
Completable.complete().toSingle { Single.just(1L) }
I get errors. Is there a missing function in Completable
or am I overlooking something?
You probably want to use the andThen
opeator, which will subscribe to the source you send to it after the Completable
completes.
return Completable.complete()
.andThen(Single.just(1L))
As @akarnokd said, this is a case of non-dependent continuations.
In case of your source needing to be resolved at runtime, this would be a deferred-dependent continuation, and you'd need to defer
it:
return Completable.complete()
.andThen(Single.defer(() -> Single.just(1L)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With