Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Progress in whenAll() and whenAllResult() #131

Open
wrozwad opened this issue May 22, 2017 · 0 comments
Open

Progress in whenAll() and whenAllResult() #131

wrozwad opened this issue May 22, 2017 · 0 comments

Comments

@wrozwad
Copy link

wrozwad commented May 22, 2017

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);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant