0
votes

I'm using retrofit2 with rxjava2 to make multiple api calls in sequence. I make a request in order to get a list o element. after that, I need to make a sequence of request (not in parallel) for each object.

SOLVED with a recursive function

1

1 Answers

0
votes

If you just want to execute each item for an array. Just simply use Observable.just() or Observable.fromIterable()

    List<String> list = Arrays
            .asList("One", "Two", "Three", "Four", "Five");

    Observable<String> observable = Observable.from(list);

    observable.subscribe(new Subscriber<String>() {
        public void onStart() {
            System.out.println("onStart");
        }

        public void onCompleted() {
            System.out.println("Completed!");
        }

        public void onError(Throwable e) {
            System.out.println("Exception thrown: " + e);
        }

        public void onNext(String s) {
            System.out.println("Next element: " + s);
        }
    });

And the result is

onStart
Next element: One
Next element: Two
Next element: Three
Next element: Four
Next element: Five
Completed!