Class CompletableFuture<R,S,T extends CompletableTask<R,S>>

java.lang.Object
de.linusdev.lutils.async.AbstractFuture<R,S,T>
de.linusdev.lutils.async.completeable.CompletableFuture<R,S,T>
All Implemented Interfaces:
Future<R,S>, HasAsyncManager

public class CompletableFuture<R,S,T extends CompletableTask<R,S>> extends AbstractFuture<R,S,T>
A Future which can be completed with the complete(Object, Object, AsyncError) method. This method will then call all listeners (see, ...) in the current Thread.

For the usage in combination with a CompletableTask, see CompletableTask.

Example:

 //Create the future
 var future = CompletableFuture.<String, Nothing>create(asyncManager);

 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();

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