Created
September 4, 2016 00:19
-
-
Save asarkar/5306c82fcf62f5b95ad723436d2ed5d1 to your computer and use it in GitHub Desktop.
RxJava Backpressure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ConnectableFlowable<Integer> pub = Flowable.range(1, 10000) | |
.publish(); | |
pub.debounce(1, SECONDS) | |
.subscribeOn(computation()) | |
.subscribe(new DefaultSubscriber<Integer>() { | |
@Override | |
public void onStart() { | |
request(1); | |
} | |
@Override | |
public void onComplete() { | |
System.out.println("Done."); | |
} | |
@Override | |
public void onError(Throwable e) { | |
System.err.println("Oh shit!"); | |
e.printStackTrace(); | |
} | |
@Override | |
public void onNext(Integer integer) { | |
System.out.println(String.format("slow: %d on thread: %s", | |
integer, Thread.currentThread().getName())); | |
request(1); | |
} | |
}); | |
pub.subscribe(x -> System.out.println(String.format("fast: %d on thread: %s", | |
x, Thread.currentThread().getName()))); | |
pub.connect(); | |
Thread.sleep(5 * 60 * 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment