Created
November 5, 2015 07:33
-
-
Save NiteshKant/0cd350faee7d82b31913 to your computer and use it in GitHub Desktop.
Pagination with 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
import rx.Observable; | |
public class Pager { | |
public static void main(String[] args) { | |
Observable.range(1, 1000) | |
.window(10) | |
.doOnNext(nextBatch -> System.out.println("Next page.")) | |
.flatMap(nums -> nums, 1) | |
.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually not, if the source supports backpressure. If you were to replace
Observable.range(1, 1000)
with a real HTTP request over the wire, you would make calls for a page perrequest(n)
from the subscriber. So, you would just be querying one page at a time from the server.I think what is more interesting in what you are asking is how does someone navigate between pages, eg: prev, next, jump to page # usecases. Since, RxJava backpressure always "moves forward", there is no way to address that solely by using backpressure.