Continuation

interface Continuation 
<TResult, TContinuationResult>

A function that is called to continue execution after completion of a Task .

Parameters
<TResult>

the Task's result type

<TContinuationResult>

the Continuation's result type

Summary

Public functions

TContinuationResult!
then (task:  Task <TResult!>)

Returns the result of applying this Continuation to task .

Public functions

then

fun  then 
(task:  Task 
<TResult!>): TContinuationResult!

Returns the result of applying this Continuation to task .

To propagate failure from the completed Task call getResult and allow the RuntimeExecutionException to propagate. The RuntimeExecutionException will be unwrapped such that the Task returned by continueWith or continueWithTask fails with the original exception.

To suppress specific failures call getResult 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 getResult with isSuccessful :

 task 
 . 
 continueWith 
 ( 
 new 
  
 Continuation<String 
 , 
  
 String 
> () 
  
 { 
  
 @Override 
  
 public 
  
 String 
  
 then 
 ( 
 Task<String> 
  
 task 
 ) 
  
 { 
  
 if 
  
 ( 
 task 
 . 
 isSuccessful 
 ()) 
  
 { 
  
 return 
  
 task 
 . 
 getResult 
 (); 
  
 } 
  
 else 
  
 { 
  
 return 
  
 DEFAULT_VALUE 
 ; 
  
 } 
  
 } 
 } 
Parameters
task:  Task <TResult!>

the completed Task. Never null

Throws
java.lang.Exception

if the result couldn't be produced

Create a Mobile Website
View Site in Mobile | Classic
Share by: