Handles the async (i.e. the continuation does return a Task) continuation case, passing the results of the given Task through to the given continuation to get a new Task. The TaskCompletionSource's results are only set when the new Task has completed, unwrapping the results of the task returned by t
(
final Task<TContinuationResult>.TaskCompletionSource tcs,
final Continuation<TResult, Task<TContinuationResult>> continuation,
final Task<TResult> task, final Executor executor)
| 501 | * scheduled on a different thread). |
| 502 | */ |
| 503 | private static <TContinuationResult, TResult> void completeAfterTask( |
| 504 | final Task<TContinuationResult>.TaskCompletionSource tcs, |
| 505 | final Continuation<TResult, Task<TContinuationResult>> continuation, |
| 506 | final Task<TResult> task, final Executor executor) { |
| 507 | executor.execute(new Runnable() { |
| 508 | public void run() { |
| 509 | try { |
| 510 | Task<TContinuationResult> result = continuation.then(task); |
| 511 | if (result == null) { |
| 512 | tcs.setResult(null); |
| 513 | } else { |
| 514 | result.continueWith(new Continuation<TContinuationResult, Void>() { |
| 515 | public Void then(Task<TContinuationResult> task) { |
| 516 | if (task.isCancelled()) { |
| 517 | tcs.setCancelled(); |
| 518 | } else if (task.isFaulted()) { |
| 519 | tcs.setError(task.getError()); |
| 520 | } else { |
| 521 | tcs.setResult(task.getResult()); |
| 522 | } |
| 523 | return null; |
| 524 | } |
| 525 | }); |
| 526 | } |
| 527 | } catch (Exception e) { |
| 528 | tcs.setError(e); |
| 529 | } |
| 530 | } |
| 531 | }); |
| 532 | } |
| 533 | |
| 534 | private void runContinuations() { |
| 535 | synchronized (lock) { |
no test coverage detected