I have a list of objects which should be passed to an API sequentially and need a final callback when all calls are completed. The code structure looks like
//Singleton class
public class RestAPIManager {
public Completable doSomething(A a) {
//Make API call here and return Completeable
}
}
//Class from which the above API call is made
public class FragmentA extends Fragment {
List<A> aList = new ArrayList<A>;
//This method should return completable after all calls are made
private Completable callDoSomething(List<A> data) {
// The code that I tried
Observable.just(data)
.flatMap(new <List<A>, Observable<?>>() {
@Override
public Observable<?> call(List<A> dataList) {
//WHAT SHOULD BE RETURNED FROM HERE
for (A a : dataList) {
RestAPIManager.getInstance().doSomething(a)
}
}
})
.doOnCompleted(new Action0() {
@Override
public void call() {
}
})
.doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
}
})
.toCompletable();
}
}
I have just started on using RxJava so am really not sure of how to go ahead with this.