Class CompletableTask<R,S>
java.lang.Object
de.linusdev.lutils.async.completeable.CompletableTask<R,S>
- Type Parameters:
R- result typeS- secondary type
- All Implemented Interfaces:
HasAsyncManager,PTask<R,,S> Task<R,S>
A
Example:
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull CompletableFuture<R,S, CompletableTask<R, S>> consumeAndQueue(@Nullable Consumer<Future<R, S>> consumer) @NotNull ComputationResult<R,S> Executes this task in the current thread.@NotNull AsyncManagerabstract voidstart(@NotNull CompletableFuture<R, S, CompletableTask<R, S>> future) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.linusdev.lutils.async.PTask
queue, queue, queue, queue, queueAndSetBeforeExecutionListener, queueAndWait, queueAndWriteToFile
-
Constructor Details
-
CompletableTask
-
-
Method Details
-
executeHere
Description copied from interface:Task- Specified by:
executeHerein interfaceTask<R,S> - Returns:
ComputationResultresult.- See Also:
-
consumeAndQueue
@NotNull public @NotNull CompletableFuture<R,S, consumeAndQueueCompletableTask<R, S>> (@Nullable @Nullable Consumer<Future<R, S>> consumer) -
start
public abstract void start(@NotNull @NotNull CompletableFuture<R, S, throws CannotQueueTaskExceptionCompletableTask<R, S>> future) - Throws:
CannotQueueTaskException
-
getAsyncManager
- Specified by:
getAsyncManagerin interfaceHasAsyncManager
-