Adds an Task-based continuation to this task that will be scheduled using the executor, returning a new task that completes after the task returned by the continuation has completed.
(
final Continuation<TResult, Task<TContinuationResult>> continuation, final Executor executor)
| 368 | * returning a new task that completes after the task returned by the continuation has completed. |
| 369 | */ |
| 370 | public <TContinuationResult> Task<TContinuationResult> continueWithTask( |
| 371 | final Continuation<TResult, Task<TContinuationResult>> continuation, final Executor executor) { |
| 372 | boolean completed = false; |
| 373 | final Task<TContinuationResult>.TaskCompletionSource tcs = Task.<TContinuationResult> create(); |
| 374 | synchronized (lock) { |
| 375 | completed = this.isCompleted(); |
| 376 | if (!completed) { |
| 377 | this.continuations.add(new Continuation<TResult, Void>() { |
| 378 | public Void then(Task<TResult> task) { |
| 379 | completeAfterTask(tcs, continuation, task, executor); |
| 380 | return null; |
| 381 | } |
| 382 | }); |
| 383 | } |
| 384 | } |
| 385 | if (completed) { |
| 386 | completeAfterTask(tcs, continuation, this, executor); |
| 387 | } |
| 388 | return tcs.getTask(); |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Adds an asynchronous continuation to this task, returning a new task that completes after the |