I have a special need for an observable.
Usually, my observables run in a different thread. But, sometimes they need to block another thread in the middle of subscription. Something the way a future behaves.
An example:
val o = Observable.create(/* computation */)
.subscribeOn(Schedulers.newThread())
.observeOn(/* current thread */);
val s = o.subscribe(/* subscriber */);`
Suddenly, an event happens on yet another thread that signals the current thread that it should wait for the execution of the subscription s
. (An example would be Android's onPause
.)
How do I do that? How do I wait on the subscription s
and even possibly retrieve all of the results?
(Subjects?)
The simplest solution for this seems to be:
Observable#cache()
. (If your observable is a stream of values, use an appropriate Subject and use that as the observable.)