Jul 21, 2017 · 1 min read
This will buffer elements and emit them immediately after the valve is open. To pause/resume a timer, I came up with this
Observable.interval(0, 1, TimeUnit.SECONDS)
.filter(tick -> !isPaused.get())
.map(tick -> durationRemaining--)
.takeUntil(secondsLeft -> secondsLeft == 0);where isPaused is an AtomicBoolean
Might not be the most precise timer, but it worked for my scenario, tho I’d love to see a better solution.