I'm struggling with RxJava2. I want to perform a function on each item of a list. This function :
public void function(final Result result) {
FirebaseFirestore.getInstance().collection(COLLECTION_NAME).document(result.getId()).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
// do some operation
}
});
}
This function is async and use FirebaseFirestore.
So I tried to use RxJava2 on my list to call the function for every item:
Observable.fromIterable(resultList)
.concatMap(result -> Observable.fromCallable(new Callable<String>() {
@Override
public String call() throws Exception {
function(result);
return "ok";
}
}))
.subscribe(r -> {
// do some operation when all firebase async tasks are done
});
The concatMap works and the function is called for every item of the list. The problem is that I need a callback when all firebase async tasks are done.
Any help would be much appreciated.