What I wanted to do is to have a Flowable with a backpressure buffer of one item that keeps the latest one produced from a stream.
I've tried to use Flowable.onBackpressureBuffer(1, () -> {}, BackpressureOverflowStrategy.DROP_OLDEST). However, it doesn't work as I expected
Flowable.range(0, 10_000)
.onBackpressureBuffer(1, {}, BackpressureOverflowStrategy.DROP_OLDEST)
.observeOn(Schedulers.computation())
.subscribe {
println(it)
Thread.sleep(5)
}
The output I expected is a sequence of integers, not necessarily contiguous, that should includes the last item 9,999. However, it only printed the first a few contiguous numbers like 0, 1, 2, 3, 4..., different each time, but not the last number 9,999.