Class Tasks

java.lang.Object
dev.ua.theroer.magicutils.platform.Tasks

public final class Tasks extends Object
Convenience helpers for scheduling tasks with Platform.
  • Method Details

    • scheduler

      public static TaskScheduler scheduler(@Nullable @Nullable Platform platform)
      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 instance
      task - 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 instance
      supplier - 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 instance
      stage - source stage
      Returns:
      future completing on main thread
    • failedFuture

      public static <T> CompletableFuture<T> failedFuture(Throwable error)
      Creates a failed future on Java 8.
      Type Parameters:
      T - future type
      Parameters:
      error - error to propagate
      Returns:
      failed future