Skip to content

Commit 51d8c0c

Browse files
author
Tomasz Lelek
committed
BEAL-572 onBackpressure operations
1 parent 2065c3c commit 51d8c0c

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎rxjava/src/main/java/com/baelding/rxjava/ComputeFunction.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ public static void compute(Observable<Integer> v) {
3434
}
3535

3636

37+
public static void compute(Long v) {
38+
try {
39+
System.out.println("compute integer v: " + v);
40+
Thread.sleep(1000);
41+
} catch (InterruptedException e) {
42+
e.printStackTrace();
43+
}
44+
}
3745
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.baelding.rxjava;
2+
3+
4+
import rx.BackpressureOverflow;
5+
import rx.Observable;
6+
import rx.schedulers.Schedulers;
7+
8+
import java.util.concurrent.TimeUnit;
9+
10+
public class HotObservableOnBackPressure {
11+
public static void main(String[] args) throws InterruptedException {
12+
Observable.range(1, 1_000_000)
13+
.onBackpressureBuffer(16, () -> {
14+
},
15+
BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST)
16+
.observeOn(Schedulers.computation())
17+
.subscribe(e -> {
18+
}, Throwable::printStackTrace);
19+
20+
21+
Observable.interval(1, TimeUnit.MINUTES)
22+
.onBackpressureDrop()
23+
// .onBackpressureLatest()
24+
.observeOn(Schedulers.io())
25+
.doOnNext(ComputeFunction::compute)
26+
.subscribe(v -> {
27+
}, Throwable::printStackTrace);
28+
Thread.sleep(10_000);
29+
30+
}
31+
}

0 commit comments

Comments
 (0)