I have an rpc call in a for-loop to receive a list of elements. The problem I have is that the return statement of the method is called before the for-loop is finished. So there a possibility to force the return statement to wait for the loop to finish?
public List<SOMETHING> getList() {
List<SOMETHING> list = ...;
for (A FEW REPETITIONS) {
RPC-CALL() {
public void onSuccess(List<SOMETHING> result) {
list.addAll(result);
}
}
}
return list;
}
I think you need to use CountDownLatch, you can initialize the counter to number of rpc calls you are making. Decrease the count on getting reply for your rpc calls and wait for the replies using countDownLatch.await()