BEAL-572 onBackpressure operations

This commit is contained in:
Tomasz Lelek 2017-02-01 16:43:15 +01:00
parent 2065c3ca51
commit 51d8c0cdb7
2 changed files with 39 additions and 0 deletions

View File

@ -34,4 +34,12 @@ public class ComputeFunction {
}
public static void compute(Long v) {
try {
System.out.println("compute integer v: " + v);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,31 @@
package com.baelding.rxjava;
import rx.BackpressureOverflow;
import rx.Observable;
import rx.schedulers.Schedulers;
import java.util.concurrent.TimeUnit;
public class HotObservableOnBackPressure {
public static void main(String[] args) throws InterruptedException {
Observable.range(1, 1_000_000)
.onBackpressureBuffer(16, () -> {
},
BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST)
.observeOn(Schedulers.computation())
.subscribe(e -> {
}, Throwable::printStackTrace);
Observable.interval(1, TimeUnit.MINUTES)
.onBackpressureDrop()
// .onBackpressureLatest()
.observeOn(Schedulers.io())
.doOnNext(ComputeFunction::compute)
.subscribe(v -> {
}, Throwable::printStackTrace);
Thread.sleep(10_000);
}
}