Class EventTask

  • Direct Known Subclasses:
    EventTask.Basic, EventTask.WithContinuation

    public abstract class EventTask
    extends java.lang.Object
    Represents a task that can be returned by a EventHandler which allows event handling to be suspended and resumed at a later time, and executing event handlers completely or partially asynchronously.

    By default will all event handlers be executed on the thread the event was posted, using event tasks this behavior can be altered.

    • Method Detail

      • requiresAsync

        public abstract boolean requiresAsync()
        Whether this EventTask is required to be called asynchronously.

        If this method returns true, the event task is guaranteed to be executed asynchronously from the current thread. Otherwise, the event task may be executed on the current thread or asynchronously.

        Returns:
        Requires async
      • of

        public static EventTask.Basic of​(java.lang.Runnable task)
        Creates a basic EventTask from the given Runnable. The task isn't guaranteed to be executed asynchronously (requiresAsync() always returns false).
        Parameters:
        task - The task
        Returns:
        The event task
      • async

        public static EventTask.Basic async​(java.lang.Runnable task)
        Creates a basic async EventTask from the given Runnable. The task is guaranteed to be executed asynchronously (requiresAsync() always returns true).
        Parameters:
        task - The task
        Returns:
        The async event task
      • withContinuation

        public static EventTask.WithContinuation withContinuation​(java.util.function.Consumer<Continuation> task)
        Creates an continuation based EventTask from the given Consumer. The task isn't guaranteed to be executed asynchronously (requiresAsync() always returns false).
        Parameters:
        task - The task to execute
        Returns:
        The event task
      • asyncWithContinuation

        public static EventTask.WithContinuation asyncWithContinuation​(java.util.function.Consumer<Continuation> task)
        Creates an async continuation based EventTask from the given Consumer. The task is guaranteed to be executed asynchronously (requiresAsync() always returns false).
        Parameters:
        task - The task to execute
        Returns:
        The event task
      • resumeWhenComplete

        public static EventTask.WithContinuation resumeWhenComplete​(java.util.concurrent.CompletableFuture<?> future)
        Creates an continuation based EventTask for the given CompletableFuture. The continuation will be notified once the given future is completed.
        Parameters:
        future - The task to wait for
        Returns:
        The event task