How to buffer only the last emission from rx.Observable during backpressure

I have rx.Observable which emits the progress of the task up to onNext() . onNext() can occur so quickly that the Observer cannot keep up, resulting in backpressure . I would like to handle back pressure only by buffering the last radiation from the Observable .

For instance:

  • Observable emits 1 and Observer gets 1 .
  • While the Observer is still processing 1 , the Observable allocates 2 , 3, and 4 .
  • Observer completes processing 1 and starts processing 4 (outliers 2 and 3 ).

It seems like this will be a common case for handling progress in the Rx Observable, since you usually care about updating your interface with the latest progress information. However, I could not figure out how to do this.

Does anyone know how this can be achieved with RxJava?

+6
source share
2 answers
+8
source

Observable.debounce sounds the way you need it. In the example below, the last radiation from only 200 ms observed in each window will be sent to the observer.

 observable .debounce(200, TimeUnit.MILLISECONDS) .subscribe(observer); 
0
source

All Articles