Class AsyncTask
java.lang.Object
org.tavall.couriers.api.concurrent.AsyncTask
AsyncTask relies on preview features of the Java platform:
AsyncTaskrefers to one or more preview APIs:FailedException,TimeoutException.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordConfiguration knobs for the scope. -
Method Summary
Modifier and TypeMethodDescriptionstatic Threadstatic <T> TrunAnySuccessAsync(Collection<? extends Callable<? extends T>> tasks, AsyncTask.ScopeOptions options) "First success wins" helper: cancels the other subtasks when one succeeds.static <T> Tstatic <T> TrunAsync(Callable<? extends T> task, AsyncTask.ScopeOptions options) Runs one task "async inside, sync outside": fork in a new (virtual) thread, join, return result.static <T> CompletableFuture<T> static <T> CompletableFuture<T> runFuture(Callable<? extends T> task, AsyncTask.ScopeOptions options) static <T> List<T> runMultipleAsync(Collection<? extends Callable<? extends T>> tasks) static <T> List<T> runMultipleAsync(Collection<? extends Callable<? extends T>> tasks, AsyncTask.ScopeOptions options) Runs tasks concurrently and returns results, FAIL-FAST style (throws if any task fails).static <T> BatchResult<T> runMultipleAsync(List<? extends Callable<? extends T>> tasks, AsyncTask.ScopeOptions options, int cancelAfterFailures, boolean throwOnFailure) The "boolean knobs" batch runner:static String
-
Method Details
-
runAsync
public static <T> T runAsync(Callable<? extends T> task, AsyncTask.ScopeOptions options) throws InterruptedException, StructuredTaskScope.TimeoutExceptionPREVIEW, StructuredTaskScope.FailedExceptionPREVIEW Runs one task "async inside, sync outside": fork in a new (virtual) thread, join, return result. Uses Joiner.anySuccessfulResultOrThrow() (single task: result-or-throw). :contentReference[oaicite:6]{index=6} -
runAsync
public static <T> T runAsync(Callable<? extends T> task) throws InterruptedException, StructuredTaskScope.TimeoutExceptionPREVIEW, StructuredTaskScope.FailedExceptionPREVIEW -
runMultipleAsync
public static <T> List<T> runMultipleAsync(Collection<? extends Callable<? extends T>> tasks, AsyncTask.ScopeOptions options) throws InterruptedException, StructuredTaskScope.TimeoutExceptionPREVIEW, StructuredTaskScope.FailedExceptionPREVIEW Runs tasks concurrently and returns results, FAIL-FAST style (throws if any task fails). This is the clean "all must succeed" policy. :contentReference[oaicite:7]{index=7} -
runMultipleAsync
public static <T> List<T> runMultipleAsync(Collection<? extends Callable<? extends T>> tasks) throws InterruptedException, StructuredTaskScope.TimeoutExceptionPREVIEW, StructuredTaskScope.FailedExceptionPREVIEW -
runMultipleAsync
public static <T> BatchResult<T> runMultipleAsync(List<? extends Callable<? extends T>> tasks, AsyncTask.ScopeOptions options, int cancelAfterFailures, boolean throwOnFailure) throws InterruptedException, StructuredTaskScope.TimeoutExceptionPREVIEW, BatchFailedException The "boolean knobs" batch runner:cancelAfterFailures: - 0 => never cancel early (wait for all) - 1 => cancel on first failure (fail-fast cancellation) - N => cancel after N failures
throwOnFailure: - true => throw BatchFailedException if any FAILED outcomes exist - false => always return BatchResult
Uses Joiner.allUntil(predicate): cancels scope when predicate returns true, and still yields all subtasks (some may be UNAVAILABLE). :contentReference[oaicite:9]{index=9}
-
runAnySuccessAsync
public static <T> T runAnySuccessAsync(Collection<? extends Callable<? extends T>> tasks, AsyncTask.ScopeOptions options) throws InterruptedException, StructuredTaskScope.TimeoutExceptionPREVIEW, StructuredTaskScope.FailedExceptionPREVIEW "First success wins" helper: cancels the other subtasks when one succeeds. :contentReference[oaicite:13]{index=13} -
runFuture
public static <T> CompletableFuture<T> runFuture(Callable<? extends T> task, AsyncTask.ScopeOptions options) -
runFuture
-
newThread
-
unwrapMessage
-
AsyncTaskwhen preview features are enabled.