Skip to content

Instantly share code, notes, and snippets.

@asarkar
Created September 4, 2016 00:19
Show Gist options
  • Select an option

  • Save asarkar/5306c82fcf62f5b95ad723436d2ed5d1 to your computer and use it in GitHub Desktop.

Select an option

Save asarkar/5306c82fcf62f5b95ad723436d2ed5d1 to your computer and use it in GitHub Desktop.

Revisions

  1. @abhijitsarkar abhijitsarkar created this gist Sep 4, 2016.
    36 changes: 36 additions & 0 deletions Backpressure.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    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);