Package com.velocitypowered.api.event
Interface EventTask
-
public interface EventTaskRepresents a task that can be returned by aEventHandlerwhich 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 Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static EventTaskasync(Runnable task)voidexecute(Continuation continuation)Runs this event task with the givenContinuation.booleanrequiresAsync()Whether thisEventTaskis required to be called asynchronously.static EventTaskresumeWhenComplete(CompletableFuture<?> future)Creates a continuation basedEventTaskfor the givenCompletableFuture.static EventTaskwithContinuation(Consumer<Continuation> task)
-
-
-
Method Detail
-
requiresAsync
boolean requiresAsync()
Whether thisEventTaskis 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
-
execute
void execute(Continuation continuation)
Runs this event task with the givenContinuation. The continuation must be notified when the task is completed, either withContinuation.resume()if the task was successful orContinuation.resumeWithException(Throwable)if an exception occurred.The
Continuationmay only be resumed once, or anIllegalStateExceptionwill be thrown.The
Continuationdoesn't need to be notified during the execution of this method, this can happen at a later point in time and from another thread.- Parameters:
continuation- The continuation
-
async
static EventTask async(Runnable task)
Creates a basic asyncEventTaskfrom the givenRunnable. The task is guaranteed to be executed asynchronously (requiresAsync()always returnstrue).- Parameters:
task- The task- Returns:
- The async event task
-
withContinuation
static EventTask withContinuation(Consumer<Continuation> task)
Creates a continuation basedEventTaskfrom the givenConsumer. The task isn't guaranteed to be executed asynchronously (requiresAsync()always returnsfalse).- Parameters:
task- The task to execute- Returns:
- The event task
-
resumeWhenComplete
static EventTask resumeWhenComplete(CompletableFuture<?> future)
Creates a continuation basedEventTaskfor the givenCompletableFuture. The continuation is resumed upon completion of the givenfuture, whether it is completed successfully or not.- Parameters:
future- The task to wait for- Returns:
- The event task
-
-