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

Progress in whenAll() and whenAllResult() #131

@wrozwad

Description

@wrozwad

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions