Otherwise, values may be emitted by the observable before a subscriber is attached to consume them.
That’s like going to the grocery store and then tossing everything in the trash can as soon as you get home.
javaHere’s my class that retries web service calls.
It’s used by the RequestPager presented later onScheduling Page RequestsIn order to manage page request, three things are needed:A queue of Suppliers; each supplier is for fetching a different page.
An ExecutorService that will service the queue.
This is only for servicing this queue.
If a page request fails, the pager will call shutdownNow on it, so you don’t want to share this executor with any code outside this particular set of page requests.
An Observable to emit the page results as they are retrieved.
In addition, here’s a few things you will need to know a priori:expectedCount: The total number of objects that you are expecting to be returned.
pageSize: The number of objects to be returned by each page request.
retryAttempts: If a page request fails , how many times to you want to reattempt the request.
threadCount: The number of simultaneous page requests that are allowed.
It’s helpful to peek ahead to see how we would set up and use the RequestPager:RequestPager.
javaBelow is the implementation of the request pager.
Again, the general flow of usage is:Create a new request pager: var pager = new RequestPager<List<MyObject>>(function, retryAttempts, threadCount);Build a request runner from the pager: var runner = pager.
build(expectedCount, pageSize);Subscribe to consume results: runner.
);Start fetching pages: runner.