MCPcopy Create free account
hub / github.com/BoltsFramework/Bolts-Java / completeAfterTask

Method completeAfterTask

Bolts/src/bolts/Task.java:503–532  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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) {

Callers 2

thenMethod · 0.95
continueWithTaskMethod · 0.95

Calls 1

executeMethod · 0.80

Tested by

no test coverage detected