Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2012-2015, Inc. or its affiliates. All Rights Reserved.
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not
   * use this file except in compliance with the License. A copy of the License is
   * located at
  * or in the "license" file accompanying this file. This file is distributed on
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.

Asynchronous task that is executed when all Promises passed to its constructor are ready (null parameter is considered ready).

Should be created in the context of AsyncScope.doAsync() method, from doExecute() or from TryCatchFinally do... methods. Exceptions thrown from doExecute() are delivered asynchronously to the wrapping TryCatchFinally.doCatch(java.lang.Throwable) method or rethrown from AsyncScope.eventLoop() if no wrapping TryCatchFinally is found.

Example of using Task to implement asynchronous function that sums parameters when both of them are ready:

 public Promise<Integer> sum(Promise<Integer> a, Promise<Integer> b) {
     Settable<Integer> result = new Settable<Integer>();
     new Task(a, b) {
         public void doExecute() {
             result.set(a.get() + b.get());
     return result;

 public abstract class Task extends AsyncContextAware {
     private TaskContext context;
     public Task(Promise<?>... waitFor) {
     public Task(boolean daemon, Promise<?>... waitFor) {
          = new TaskContext(thisdaemonwaitFor);
     private Task(Boolean daemon, Promise<?>... waitFor) {
          = new TaskContext(thisdaemonwaitFor);
     public Task(AsyncContextAware parentboolean daemon, Promise<?>... waitFor) {
          = new TaskContext(parent.getContext(), thisdaemonwaitFor);
     public Task(AsyncContextAware parent, Promise<?>... waitFor) {
          = new TaskContext(parent.getContext(), thisnullwaitFor);
     protected Task(AsyncContextAware parentBoolean daemonString parentTaskMethodNameboolean hideParentTaskMethodName,
             int skipStackLines, Promise<?>... waitFor) {
          = new TaskContext(parent.getContext(), thisdaemonparentTaskMethodNamehideParentTaskMethodName,
     protected Task(Boolean daemonString parentTaskMethodNameboolean hideParentTaskMethodNameint skipStackLines,
             Promise<?>... waitFor) {
          = new TaskContext(thisdaemonparentTaskMethodNamehideParentTaskMethodNameskipStackLineswaitFor);
     public String getName() {
         return .getName();
     public void setName(String name) {
     public StackTraceElement[] getStackTrace() {
         return .getStackTrace().getStackTrace();
        return ;
    public String toString() {
        return .toString();
    protected abstract void doExecute() throws Throwable;
New to GrepCode? Check out our FAQ X