I tried below.
public static void main(String[] args) throws Exception {
Observable.interval(100L, TimeUnit.MILLISECONDS)
.onBackpressureDrop().subscribe(new Subscriber<Long>() {
@Override
public void onStart() {
request(1L);
}
@Override
public void onNext(Long t) {
System.out.println("received: " + t);
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
request(1);
}
@Override
public void onCompleted() {
System.out.println("onCompleted");
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
});
TimeUnit.SECONDS.sleep(10L);
}
I expected that the subscriber would receive the item 0, 10, 20, 30...
because onBackpressureDrop method would drop the items before the request.
But the result was 0, 1, 2, 3...
.
Also, I tried onBackpressureLatest()
but the result was the same, 0, 1, 2, 3...
.
This seem to me the same as onBackpressureBuffer
.
Do I misunderstand this method? If so, how I tried that onBackpressureDrop method would work as the marble diagram in Javadoc?