Skip to content

Instantly share code, notes, and snippets.

@asarkar
Created September 4, 2016 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asarkar/5306c82fcf62f5b95ad723436d2ed5d1 to your computer and use it in GitHub Desktop.
Save asarkar/5306c82fcf62f5b95ad723436d2ed5d1 to your computer and use it in GitHub Desktop.
RxJava Backpressure
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