Reformat Rxjava examples
This commit is contained in:
parent
10eb6bfcc0
commit
6d0dcd52fa
|
@ -5,7 +5,10 @@ import rx.schedulers.Schedulers;
|
|||
|
||||
public class ColdObservableBackpressure {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Observable.range(1, 1_000_000).observeOn(Schedulers.computation()).subscribe(v -> ComputeFunction.compute(v), Throwable::printStackTrace);
|
||||
Observable
|
||||
.range(1, 1_000_000)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
|
||||
Thread.sleep(10_000);
|
||||
|
||||
|
|
|
@ -5,9 +5,12 @@ import rx.subjects.PublishSubject;
|
|||
|
||||
public class HotObservableBackpressureBatching {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer>create();
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||
|
||||
source.window(500).observeOn(Schedulers.computation()).subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
source
|
||||
.window(500)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
|
||||
for (int i = 0; i < 1_000_000; i++) {
|
||||
source.onNext(i);
|
||||
|
|
|
@ -5,9 +5,12 @@ import rx.subjects.PublishSubject;
|
|||
|
||||
public class HotObservableBackpressureBuffering {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer>create();
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||
|
||||
source.buffer(1024).observeOn(Schedulers.computation()).subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
source
|
||||
.buffer(1024)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
|
||||
for (int i = 0; i < 1_000_000; i++) {
|
||||
source.onNext(i);
|
||||
|
|
|
@ -7,11 +7,12 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class HotObservableBackpressureSkipping {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer>create();
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||
|
||||
source.sample(100, TimeUnit.MILLISECONDS)
|
||||
// .throttleFirst(100, TimeUnit.MILLISECONDS)
|
||||
.observeOn(Schedulers.computation()).subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
//.throttleFirst(100, TimeUnit.MILLISECONDS)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
|
||||
for (int i = 0; i < 1_000_000; i++) {
|
||||
source.onNext(i);
|
||||
|
|
|
@ -6,12 +6,21 @@ import rx.schedulers.Schedulers;
|
|||
|
||||
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
|
||||
.range(1, 1_000_000)
|
||||
.onBackpressureBuffer(16, () -> {
|
||||
}, BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(e -> {
|
||||
}, Throwable::printStackTrace);
|
||||
|
||||
Observable.range(1, 1_000_000).onBackpressureDrop().observeOn(Schedulers.io()).doOnNext(ComputeFunction::compute).subscribe(v -> {
|
||||
}, Throwable::printStackTrace);
|
||||
Observable
|
||||
.range(1, 1_000_000)
|
||||
.onBackpressureDrop()
|
||||
.observeOn(Schedulers.io())
|
||||
.doOnNext(ComputeFunction::compute)
|
||||
.subscribe(v -> {
|
||||
}, Throwable::printStackTrace);
|
||||
Thread.sleep(10_000);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package com.baelding.rxjava;
|
||||
|
||||
|
||||
import rx.schedulers.Schedulers;
|
||||
import rx.subjects.PublishSubject;
|
||||
|
||||
public class HotObservableWithoutBackpressure {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer>create();
|
||||
|
||||
source.observeOn(Schedulers.computation())
|
||||
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||
|
||||
source
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
|
||||
|
||||
for (int i = 0; i < 1_000_000; i++) {
|
||||
source.onNext(i);
|
||||
|
|
Loading…
Reference in New Issue