Package com.velocitypowered.api.event
Class EventTask
- java.lang.Object
-
- com.velocitypowered.api.event.EventTask
-
- Direct Known Subclasses:
EventTask.Basic
,EventTask.WithContinuation
public abstract class EventTask extends java.lang.Object
Represents a task that can be returned by aEventHandler
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EventTask.Basic
Represents a basicEventTask
.static class
EventTask.WithContinuation
Represents anEventTask
which receives aContinuation
throughEventTask.WithContinuation.run(Continuation)
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static EventTask.Basic
async(java.lang.Runnable task)
Creates a basic asyncEventTask
from the givenRunnable
.static EventTask.WithContinuation
asyncWithContinuation(java.util.function.Consumer<Continuation> task)
Creates an async continuation basedEventTask
from the givenConsumer
.static EventTask.Basic
of(java.lang.Runnable task)
Creates a basicEventTask
from the givenRunnable
.abstract boolean
requiresAsync()
Whether thisEventTask
is required to be called asynchronously.static EventTask.WithContinuation
resumeWhenComplete(java.util.concurrent.CompletableFuture<?> future)
Creates an continuation basedEventTask
for the givenCompletableFuture
.static EventTask.WithContinuation
withContinuation(java.util.function.Consumer<Continuation> task)
Creates an continuation basedEventTask
from the givenConsumer
.
-
-
-
Method Detail
-
requiresAsync
public abstract boolean requiresAsync()
Whether thisEventTask
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 basicEventTask
from the givenRunnable
. The task isn't guaranteed to be executed asynchronously (requiresAsync()
always returnsfalse
).- Parameters:
task
- The task- Returns:
- The event task
-
async
public static EventTask.Basic async(java.lang.Runnable task)
Creates a basic asyncEventTask
from the givenRunnable
. The task is guaranteed to be executed asynchronously (requiresAsync()
always returnstrue
).- Parameters:
task
- The task- Returns:
- The async event task
-
withContinuation
public static EventTask.WithContinuation withContinuation(java.util.function.Consumer<Continuation> task)
Creates an continuation basedEventTask
from the givenConsumer
. The task isn't guaranteed to be executed asynchronously (requiresAsync()
always returnsfalse
).- 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 basedEventTask
from the givenConsumer
. The task is guaranteed to be executed asynchronously (requiresAsync()
always returnsfalse
).- Parameters:
task
- The task to execute- Returns:
- The event task
-
resumeWhenComplete
public static EventTask.WithContinuation resumeWhenComplete(java.util.concurrent.CompletableFuture<?> future)
Creates an continuation basedEventTask
for the givenCompletableFuture
. The continuation will be notified once the given future is completed.- Parameters:
future
- The task to wait for- Returns:
- The event task
-
-