Class Tasks
java.lang.Object
dev.ua.theroer.magicutils.platform.Tasks
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> CompletableFuture<T> callOnMain(@Nullable Platform platform, Supplier<T> supplier) Runs a supplier on the main thread and returns a future.static <T> CompletableFuture<T> failedFuture(Throwable error) Creates a failed future on Java 8.static CompletableFuture<Void> Runs a task on the main thread and returns a future.static TaskSchedulerResolves the scheduler for a platform (shared fallback when null).static <T> CompletableFuture<T> thenOnMain(@Nullable Platform platform, CompletionStage<T> stage) Ensures the completion stage resolves on the main thread.
-
Method Details
-
scheduler
Resolves the scheduler for a platform (shared fallback when null).- Parameters:
platform- platform instance- Returns:
- scheduler instance
-
runOnMain
public static CompletableFuture<Void> runOnMain(@Nullable @Nullable Platform platform, Runnable task) Runs a task on the main thread and returns a future.- Parameters:
platform- platform instancetask- task to run- Returns:
- future for completion
-
callOnMain
public static <T> CompletableFuture<T> callOnMain(@Nullable @Nullable Platform platform, Supplier<T> supplier) Runs a supplier on the main thread and returns a future.- Type Parameters:
T- value type- Parameters:
platform- platform instancesupplier- supplier to run- Returns:
- future for result
-
thenOnMain
public static <T> CompletableFuture<T> thenOnMain(@Nullable @Nullable Platform platform, CompletionStage<T> stage) Ensures the completion stage resolves on the main thread.- Type Parameters:
T- value type- Parameters:
platform- platform instancestage- source stage- Returns:
- future completing on main thread
-
failedFuture
Creates a failed future on Java 8.- Type Parameters:
T- future type- Parameters:
error- error to propagate- Returns:
- failed future
-