I have an rx.Observable
which emits the progress of a task to onNext()
. The onNext()
emissions can sometimes occur so quickly that the Observer
cannot keep up, resulting in backpressure. I would like to handle the backpressure by only buffering the latest emission from the Observable
.
For example:
Observable
emits 1 andObserver
receives 1.- While
Observer
is still processing 1,Observable
emits 2, 3, and 4. Observer
finishes processing 1 and begins processing 4 (emissions 2 and 3 are dropped).
This seems like it would be a common case for handling progress in an Rx Observable since you usually only care about updating your UI with the latest progress information. However I have not been able to figure out how to do this.
Anyone know how this can be achieved with RxJava?
subscribeOn(Schedulers.io())
andobserveOn(AndroidSchedulers.mainThread())
to get it to work. – Quadrivium