Home » Java » RxJava update data after first Completable but before returning next single

RxJava update data after first Completable but before returning next single

Posted by: admin June 30, 2018 Leave a comment

Questions:

What I need to do is make a completable call (verify session token), then once that is complete, update the session token in the next request (returning the last call, which is a single).

This is what I have so far, which does the job, but it looks messy. There has to be a cleaner way to do this?
I’m looking for a solution similar to how flatmap() works but I want to return the last single.

Single<ItemsResponse> getItems() {

    return verifySessionBeforeApiRequest().andThen
    (Completable.create(new CompletableOnSubscribe() {
        @Override
        public void subscribe(CompletableEmitter e) throws Exception {
            nextRequest.setSession(getSessionId());
            e.onComplete();
        }
    })).andThen(makeFinalCall(nextRequest));
}
Answers: