I have an Observable
that emits ticks every second:
Observable.interval(0, 1, TimeUnit.SECONDS)
.take(durationInSeconds + 1));
I'd like to pause this Observable so it stops emitting numbers, and resume it on demand.
There are some gotchas:
- according to the
Observable
Javadoc,interval
operator doesn't support backpressure - the RxJava wiki about backpressure has a section about Callstack blocking as a flow-control alternative to backpressure:
Another way of handling an overproductive Observable is to block the callstack (parking the thread that governs the overproductive Observable). This has the disadvantage of going against the “reactive” and non-blocking model of Rx. However this can be a viable option if the problematic Observable is on a thread that can be blocked safely. Currently RxJava does not expose any operators to facilitate this.
Is there a way to pause an interval
Observable? Or should I implement my own 'ticking' Observable with some backpressure support?