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 and Observer receives 1.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?
onBackPressureLatest is your friend here. :)
http://reactivex.io/RxJava/javadoc/rx/Observable.html#onBackpressureLatest()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With