Interface EventTask

public interface EventTask
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.

Compatibility notice: While in Velocity 3.0.0, all event handlers still execute asynchronously (to preserve backwards compatibility), this will not be the case in future versions of Velocity. Please prepare your code by using continuations or returning an instance returned by async(Runnable).

  • Method Details

    • requiresAsync

      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.

      Requires async
    • execute

      void execute(Continuation continuation)
      Runs this event task with the given Continuation. The continuation must be notified when the task is completed, either with Continuation.resume() if the task was successful or Continuation.resumeWithException(Throwable) if an exception occurred.

      The Continuation may only be resumed once, or an IllegalStateException will be thrown.

      The Continuation doesn't need to be notified during the execution of this method, this can happen at a later point in time and from another thread.

      continuation - The continuation
    • async

      static EventTask async(Runnable task)
      Creates a basic async EventTask from the given Runnable. The task is guaranteed to be executed asynchronously (requiresAsync() always returns true).
      task - The task
      The async event task
    • withContinuation

      static EventTask withContinuation(Consumer<Continuation> task)
      Creates a continuation based EventTask from the given Consumer. The task isn't guaranteed to be executed asynchronously (requiresAsync() always returns false).
      task - The task to execute
      The event task
    • resumeWhenComplete

      static EventTask resumeWhenComplete(CompletableFuture<?> future)
      Creates a continuation based EventTask for the given CompletableFuture. The continuation is resumed upon completion of the given future, whether it is completed successfully or not.
      future - The task to wait for
      The event task