Class CompletableTask<R,S>

java.lang.Object
de.linusdev.lutils.async.completeable.CompletableTask<R,S>
Type Parameters:
R - result type
S - secondary type
All Implemented Interfaces:
HasAsyncManager, PTask<R,S>, Task<R,S>

public abstract class CompletableTask<R,S> extends Object implements PTask<R,S>
A Task, which creates a CompletableFuture when started.

Example:

 CompletableTask<String, Nothing> task = new CompletableTask<>(asyncManager) {
     @Override
     public void start(
             CompletableFuture<String, Nothing,
             CompletableTask<String, Nothing>> future
     ) {
         //Store the future for later completion or start execution...
         new Thread(() -> {
             try {
                 Thread.sleep(3000);
                 //complete the future in a different Thread
                 future.complete("Hello", Nothing.INSTANCE, null);
             } catch (Throwable e) {
                 future.complete(null, Nothing.INSTANCE,
                         new ThrowableAsyncError(e));
             }
         }).start();
     }
 };

 Task<String, Nothing> taskToReturn = task;

 //End User:
 Future<String, Nothing> f = taskToReturn.queue();
 String res = f.getResult();
 System.out.println("Result: " + res);
See Also: