I am wondering if there is a way to compose existing operators to perform the opposite of a switchMap()
.
The switchMap()
will chase after the latest emission it receives and cancel any Observable
it previously was executing. Let's say I flipped it, and I want to ignore all emissions coming to a xxxMap()
operator while it is busy with the first emission it received. It will keep ignoring emissions until it finishes emitting the current Observable
inside of it. Then it will process the next emission it receives.
Observable.interval(1, TimeUnit.SECONDS)
.doOnNext(i -> System.out.println("Source Emitted Value: " + i))
.ignoreWhileBusyMap(i -> doIntensiveProcess(i).subcribeOn(Schedulers.computation()))
.subscribe(i -> System.out.println("Subscriber received Value: " + i));
Is there a way to accomplish this? In the above example, if intensiveProcess()
were to last three seconds, the ignoreWhileBusyMap()
would process 0
but likely ignore emissions 1
and 2
coming from interval()
.It would then process 3
but likely ignore 4
and 5
, and so on...
Semaphore
but was hoping to use a purely reactive composition with existing operators. I suppose I could wrap all this up in aTransformer
though. – Christinchristina