Of course, start processing the value with the boolean set after the processing is completed:
AtomicBoolean gate = new AtomicBoolean(true); Observable.interval(200, TimeUnit.MILLISECONDS) .flatMap(v -> { if (gate.get()) { gate.set(false); return Observable.just(v).delay(500, TimeUnit.MILLISECONDS) .doAfterTerminate(() -> gate.set(true)); } else { return Observable.empty(); } }) .take(10) .toBlocking() .subscribe(System.out::println, Throwable::printStackTrace);
Edit
Alternative:
Observable.interval(200, TimeUnit.MILLISECONDS) .onBackpressureDrop() .flatMap(v -> { return Observable.just(v).delay(500, TimeUnit.MILLISECONDS); }, 1) .take(10) .toBlocking() .subscribe(System.out::println, Throwable::printStackTrace);
You can change onBackpressureDrop to onBackpressureLatest to continue with the most recent value.
source share