These are chat archives for ReactiveX/RxJava

17th
Mar 2017
Ertan Deniz
@ertanden
Mar 17 2017 12:36

Hi,

I'm pretty new in RxJava and stumbled into a problem. I have a getData method which gets data from a RESTFul service with cursor/pagination support. The following code, when there's an exception in getData starts the whole process from the beginning, but would it be possible to just retry the failed getData with the specific cursor?

How should I rewrite this code?

Flowable<Response> f = Flowable.create(emitter -> {
    long cursor = -1;
    Response response;

    do {
        response = getData(cursor);

        emitter.onNext(response);
        cursor = response.getNextCursor();
    } while (response.hasNext());

    emitter.onComplete();
}, BackpressureStrategy.BUFFER);

f.retryWhen(errors -> {
    return errors.zipWith(Flowable.range(1, 5), (err, attempt) -> {
        return Flowable.timer(2 * attempt, TimeUnit.SECONDS);
    });
});