endstone/scheduler
Classes
Type Aliases
| Name | Description |
|---|---|
TaskId |
classScheduler
Defined in <endstone/scheduler/scheduler.h>
Represents a scheduler that executes various tasks.
Methods
| Name | Description |
|---|---|
~Scheduler | |
runTask | |
runTaskLater | |
runTaskTimer | |
runTaskAsync | Returns a task that will be executed asynchronously on the next server tick. |
runTaskLaterAsync | Returns a task that will be executed asynchronously after the specified number of server ticks. |
runTaskTimerAsync | Returns a task that will be executed repeatedly (and asynchronously) until cancelled, starting after the specified number of server ticks. |
cancelTask | |
cancelTasks | |
isRunning | |
isQueued | |
getPendingTasks |
meth~Schedulervirtual
~Scheduler() =defaultmethrunTaskabstract
std::shared_ptr<Task> runTask(Plugin& plugin, std::function<void()> task) =0Returns a task that will be executed synchronously on the next server tick.
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | the reference to the plugin scheduling task |
task | std::function<void()> | the task to be run |
Returns
| Type | Description |
|---|---|
std::shared_ptr<Task> | a Task that contains the id number (nullptr if task is empty) |
methrunTaskLaterabstract
std::shared_ptr<Task> runTaskLater(Plugin& plugin, std::function<void()> task, std::uint64_t delay) =0Returns a task that will be executed synchronously after the specified number of server ticks.
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | the reference to the plugin scheduling task |
task | std::function<void()> | the task to be run |
delay | std::uint64_t | the ticks to wait before running the task |
Returns
| Type | Description |
|---|---|
std::shared_ptr<Task> | a Task that contains the id number (nullptr if task is empty) |
methrunTaskTimerabstract
std::shared_ptr<Task> runTaskTimer(Plugin& plugin, std::function<void()> task, std::uint64_t delay, std::uint64_t period) =0Returns a task that will be executed repeatedly (and synchronously) until cancelled, starting after the specified number of server ticks.
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | the reference to the plugin scheduling task |
task | std::function<void()> | the task to be run |
delay | std::uint64_t | the ticks to wait before running the task |
period | std::uint64_t | the ticks to wait between runs |
Returns
| Type | Description |
|---|---|
std::shared_ptr<Task> | a Task that contains the id number (nullptr if task is empty) |
methrunTaskAsyncabstract
std::shared_ptr<Task> runTaskAsync(Plugin& plugin, std::function<void()> task) =0Returns a task that will be executed asynchronously on the next server tick.
Remark
Asynchronous tasks should never access any Endstone API
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | the reference to the plugin scheduling task |
task | std::function<void()> | the task to be run |
Returns
| Type | Description |
|---|---|
std::shared_ptr<Task> | a Task that contains the id number (nullptr if task is empty) |
methrunTaskLaterAsyncabstract
std::shared_ptr<Task> runTaskLaterAsync(Plugin& plugin, std::function<void()> task, std::uint64_t delay) =0Returns a task that will be executed asynchronously after the specified number of server ticks.
Remark
Asynchronous tasks should never access any Endstone API
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | the reference to the plugin scheduling task |
task | std::function<void()> | the task to be run |
delay | std::uint64_t | the ticks to wait before running the task |
Returns
| Type | Description |
|---|---|
std::shared_ptr<Task> | a Task that contains the id number (nullptr if task is empty) |
methrunTaskTimerAsyncabstract
std::shared_ptr<Task> runTaskTimerAsync(Plugin& plugin, std::function<void()> task, std::uint64_t delay, std::uint64_t period) =0Returns a task that will be executed repeatedly (and asynchronously) until cancelled, starting after the specified number of server ticks.
Remark
Asynchronous tasks should never access any Endstone API
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | the reference to the plugin scheduling task |
task | std::function<void()> | the task to be run |
delay | std::uint64_t | the ticks to wait before running the task |
period | std::uint64_t | the ticks to wait between runs |
Returns
| Type | Description |
|---|---|
std::shared_ptr<Task> | a Task that contains the id number (nullptr if task is empty) |
methcancelTaskabstract
void cancelTask(TaskId id) =0Removes task from scheduler.
Parameters
| Name | Type | Description |
|---|---|---|
taskId | Id number of task to be removed |
methcancelTasksabstract
void cancelTasks(Plugin& plugin) =0Removes all tasks associated with a particular plugin from the scheduler.
Parameters
| Name | Type | Description |
|---|---|---|
plugin | Plugin& | Owner of tasks to be removed |
methisRunningabstract
bool isRunning(TaskId id) =0Check if the task currently running.
Parameters
| Name | Type | Description |
|---|---|---|
taskId | The task to check. |
Returns
| Type | Description |
|---|---|
bool | If the task is currently running. |
methisQueuedabstract
bool isQueued(TaskId id) =0Check if the task queued to be run later.
Parameters
| Name | Type | Description |
|---|---|---|
taskId | The task to check. |
Returns
| Type | Description |
|---|---|
bool | If the task is queued to be run. |
methgetPendingTasksabstract
std::vector<Task*> getPendingTasks() =0Returns a vector of all pending tasks.
The ordering of the tasks is NOT related to their order of execution.
Returns
| Type | Description |
|---|---|
std::vector<Task*> | Pending tasks |
classTask
Defined in <endstone/scheduler/task.h>
Represents a task being executed by the scheduler.
meth~Taskvirtual
~Task() =defaultmethgetTaskIdabstractconst
TaskId getTaskId() const =0Returns the taskId for the task.
methgetOwnerabstractconst
Plugin* getOwner() const =0Returns the Plugin that owns this task.
methisSyncabstractconst
bool isSync() const =0Returns true if the Task is a sync task.
Returns
| Type | Description |
|---|---|
bool | true if the task is run by server thread |
methisCancelledabstractconst
bool isCancelled() const =0Returns true if this task has been cancelled.
Returns
| Type | Description |
|---|---|
bool | true if the task has been cancelled |
methcancelabstract
void cancel() =0Attempts to cancel this task.
typeTaskId
std::uint32_t TaskId