Reformat Rxjava examples

This commit is contained in:
pivovarit 2017-02-05 08:30:32 +01:00
parent 10eb6bfcc0
commit 6d0dcd52fa
6 changed files with 36 additions and 18 deletions

View File

@ -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);

View File

@ -7,7 +7,10 @@ public class HotObservableBackpressureBatching {
public static void main(String[] args) throws InterruptedException {
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);

View File

@ -7,7 +7,10 @@ public class HotObservableBackpressureBuffering {
public static void main(String[] args) throws InterruptedException {
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);

View File

@ -11,7 +11,8 @@ public class HotObservableBackpressureSkipping {
source.sample(100, TimeUnit.MILLISECONDS)
//.throttleFirst(100, TimeUnit.MILLISECONDS)
.observeOn(Schedulers.computation()).subscribe(ComputeFunction::compute, Throwable::printStackTrace);
.observeOn(Schedulers.computation())
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
for (int i = 0; i < 1_000_000; i++) {
source.onNext(i);

View File

@ -6,11 +6,20 @@ 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 -> {
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 -> {
Observable
.range(1, 1_000_000)
.onBackpressureDrop()
.observeOn(Schedulers.io())
.doOnNext(ComputeFunction::compute)
.subscribe(v -> {
}, Throwable::printStackTrace);
Thread.sleep(10_000);

View File

@ -1,6 +1,5 @@
package com.baelding.rxjava;
import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject;
@ -8,10 +7,10 @@ public class HotObservableWithoutBackpressure {
public static void main(String[] args) throws InterruptedException {
PublishSubject<Integer> source = PublishSubject.<Integer> create();
source.observeOn(Schedulers.computation())
source
.observeOn(Schedulers.computation())
.subscribe(ComputeFunction::compute, Throwable::printStackTrace);
for (int i = 0; i < 1_000_000; i++) {
source.onNext(i);
}