I'm trying to pause / resume a delayed operation using rx-Java
, and surprisingly I can't find any details on how to do that.
Obviously, I know how to do it by creating a specific Timer
thread and keeping track of the time, but I'm looking for a more elegant and reactive way.
I have three different observables, playDetected
, one for pauseDetected
and one for stopDetected
. I want to emit something after a certain delay of PLAY
, but pause when my pause observable emits, and resume when I get another PLAY
What I have so far: (it's written in kotlin
but Java
, pseudo-code or any language will do for an answer)
val playSubscription = playDetected
.delay(DELAY, SECONDS, schedulers.computation)
.subscribe { emitFinalEvent(it) }
stopDetected.subscribe { playSubscription.unsubscribe() }
My delay works, and when I detect a STOP
, it successfully removes the delay so that the next PLAY
can start it again. But how to pause and resume when pauseDetected
emits something???