This repository was archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 522
This repository was archived by the owner on Sep 2, 2020. It is now read-only.
Progress in whenAll() and whenAllResult() #131
Copy link
Copy link
Open
Description
HELLo moto ;)
Is there any possibility to have a "progress listener" to completion of whenAll()
and whenAllResult()
methods? For now we have only onSuccess(new Continuation<TTaskResult, TContinuationResult>())
listener that is indicated when all tasks are completed. But I want to show progress indicator to user and can't get the idea how to do that.
edit:
Ok, we can do that in that way
tasksList.add(
Task.callInBackground(() -> {
// do something extra heavy
return someDoubleResult;
}));
...
final Capture<Integer> currentProgress = new Capture<>(0);
final int progressCount = tasksList.size();
for (Task<Double> taskWithFinish : tasksList) {
taskWithFinish.onSuccess(task -> {
currentProgress.set(currentProgress.get() + 1);
updateProgress((float) currentProgress.get() / progressCount);
return task.getResult();
});
}
Task.whenAllResult(tasksList)
.onSuccess(new Continuation<List<Double>, Void>() {
@Override
public Void then(Task<List<Double>> task) throws Exception {
// close progress indicator
return null;
}
}, Task.UI_THREAD_EXECUTOR);
Will be nice to do that in simpler way, eg.
tasksList.add(
Task.callInBackground(() -> {
// do something extra heavy
return someDoubleResult;
}));
...
Task.whenAllResult(tasksList)
.onProgress(new Progress<Double>() {
@Override
public void onProgress(Task<Double> task, int finishedTaskNr, int tasksSumCount) {
updateProgressBar((float) finishedTaskNr / tasksSumCount);
}
})
.onSuccess(new Continuation<List<Double>, Void>() {
@Override
public Void then(Task<List<Double>> task) throws Exception {
// close progress indicator
return null;
}
}, Task.UI_THREAD_EXECUTOR);
Metadata
Metadata
Assignees
Labels
No labels