使用背压时如何在缓冲区中打印元素:
Flowable.range(1, 1000)
.onBackpressureBuffer(20, () ->{}, BackpressureOverflowStrategy.DROP_OLDEST)
.onBackpressureDrop(v -> System.out.println("Dropped.. :" + v))
.delay(0, TimeUnit.MILLISECONDS, Schedulers.io())
.doOnNext(value -> System.out.println("got " + value))
.map(value -> {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return value;
})
.observeOn(Schedulers.newThread(),false, 20)
.subscribe(
value -> System.out.println("handled: " + value),
Throwable::printStackTrace,
() -> System.out.println("completed")
);
sleep(10000);
输出:
得到 1
Dropped.. :21
Dropped.. :22
Dropped.. :23
Dropped.. :24
Dropped.. :25
。
.
.
我想
在缓冲区中
有 1 个
元素:2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
Dropped.. :21
.
.
.
我不知道这是否可能。请帮助我是反应式编程的新手
谢谢