Task<Void> task1 = ... Task<Void> task2 = ... Task<Void> task3 = ... Task<Void> combinedTask = Tasks.whenAll(task1, task2, task3); Task<String> task1 = ... Task<Integer> task2 = ... Task<Task<Integer>> nestedTask = task1.continueWithTask(new Continuation<String, Task<Integer>>() { @Override public Task<Integer> then(@NonNull Task<String> task) throws Exception { String result = task.getResult(); // Perform some operation using the result return task2; } }); Task<String> task1 = ... Task<Integer> task2 = ... Task<Integer> flattenedTask = task1.continueWithTask(new Continuation<String, Task<Integer>>() { @Override public Task<Integer> then(@NonNull Task<String> task) throws Exception { String result = task.getResult(); // Perform some operation using the result return Tasks.forResult(result.length()); } }); Task<String> task1 = ... Task<Integer> task2 = ... Task<Void> parallelTask = Tasks.whenAll(task1, task2).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(@NonNull Task<Void> task) throws Exception { // Perform some operation after both tasks are completed return task; } }); Task<String> task1 = ... Task<Integer> task2 = ... Task<Void> parallelTask = Tasks.whenAll(task1, task2).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(@NonNull Task<Void> task) throws Exception { // Perform some operation after both tasks are completed return task; } }, TaskExecutors.BACKGROUND_THREAD);


上一篇:
下一篇:
切换中文