Adds a continuation that will be scheduled using the executor, returning a new task that completes after the continuation has finished running. This allows the continuation to be scheduled on different thread.
(
final Continuation<TResult, TContinuationResult> continuation, final Executor executor)
| 334 | * scheduled on different thread. |
| 335 | */ |
| 336 | public <TContinuationResult> Task<TContinuationResult> continueWith( |
| 337 | final Continuation<TResult, TContinuationResult> continuation, final Executor executor) { |
| 338 | boolean completed = false; |
| 339 | final Task<TContinuationResult>.TaskCompletionSource tcs = Task.<TContinuationResult> create(); |
| 340 | synchronized (lock) { |
| 341 | completed = this.isCompleted(); |
| 342 | if (!completed) { |
| 343 | this.continuations.add(new Continuation<TResult, Void>() { |
| 344 | public Void then(Task<TResult> task) { |
| 345 | completeImmediately(tcs, continuation, task, executor); |
| 346 | return null; |
| 347 | } |
| 348 | }); |
| 349 | } |
| 350 | } |
| 351 | if (completed) { |
| 352 | completeImmediately(tcs, continuation, this, executor); |
| 353 | } |
| 354 | return tcs.getTask(); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Adds a synchronous continuation to this task, returning a new task that completes after the |