A function that is called to continue execution after completion of a Task.
| abstract TContinuationResult |
Returns the result of applying this Continuation to task.
To propagate failure from the completed Task call Task.getResult()
and allow the RuntimeExecutionException
to propagate. The RuntimeExecutionException will be unwrapped such that the Task
returned by
Task.continueWith(Continuation) or
Task.continueWithTask(Continuation) fails with the original exception.
To suppress specific failures call
Task.getResult(Class) and catch the exception types of interest:
task.continueWith(new Continuation<String, String>() {
@Override
public String then(Task<String> task) {
try {
return task.getResult(IOException.class);
} catch (FileNotFoundException e) {
return "Not found";
} catch (IOException e) {
return "Read failed";
}
}
}
To suppress all failures guard any calls to Task.getResult()
with Task.isSuccessful():
task.continueWith(new Continuation<String, String>() {
@Override
public String then(Task<String> task) {
if (task.isSuccessful()) {
return task.getResult();
} else {
return DEFAULT_VALUE;
}
}
}
| task | the completed Task. Never null |
|---|
| Exception | if the result couldn't be produced |
|---|