endstone/scheduler

Classes

NameDescription
SchedulerRepresents a scheduler that executes various tasks.
TaskRepresents a task being executed by the scheduler.

Type Aliases

NameDescription
TaskId

classScheduler

Defined in <endstone/scheduler/scheduler.h>

Represents a scheduler that executes various tasks.

Methods

NameDescription
~Scheduler
runTask
runTaskLater
runTaskTimer
runTaskAsyncReturns a task that will be executed asynchronously on the next server tick.
runTaskLaterAsyncReturns a task that will be executed asynchronously after the specified number of server ticks.
runTaskTimerAsyncReturns 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() =default

methrunTaskabstract

std::shared_ptr<Task> runTask(Plugin& plugin, std::function<void()> task) =0

Returns a task that will be executed synchronously on the next server tick.

Parameters

NameTypeDescription
pluginPlugin&the reference to the plugin scheduling task
taskstd::function<void()>the task to be run

Returns

TypeDescription
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) =0

Returns a task that will be executed synchronously after the specified number of server ticks.

Parameters

NameTypeDescription
pluginPlugin&the reference to the plugin scheduling task
taskstd::function<void()>the task to be run
delaystd::uint64_tthe ticks to wait before running the task

Returns

TypeDescription
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) =0

Returns a task that will be executed repeatedly (and synchronously) until cancelled, starting after the specified number of server ticks.

Parameters

NameTypeDescription
pluginPlugin&the reference to the plugin scheduling task
taskstd::function<void()>the task to be run
delaystd::uint64_tthe ticks to wait before running the task
periodstd::uint64_tthe ticks to wait between runs

Returns

TypeDescription
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) =0

Returns a task that will be executed asynchronously on the next server tick.

Remark

Asynchronous tasks should never access any Endstone API

Parameters

NameTypeDescription
pluginPlugin&the reference to the plugin scheduling task
taskstd::function<void()>the task to be run

Returns

TypeDescription
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) =0

Returns a task that will be executed asynchronously after the specified number of server ticks.

Remark

Asynchronous tasks should never access any Endstone API

Parameters

NameTypeDescription
pluginPlugin&the reference to the plugin scheduling task
taskstd::function<void()>the task to be run
delaystd::uint64_tthe ticks to wait before running the task

Returns

TypeDescription
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) =0

Returns 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

NameTypeDescription
pluginPlugin&the reference to the plugin scheduling task
taskstd::function<void()>the task to be run
delaystd::uint64_tthe ticks to wait before running the task
periodstd::uint64_tthe ticks to wait between runs

Returns

TypeDescription
std::shared_ptr<Task>a Task that contains the id number (nullptr if task is empty)

methcancelTaskabstract

void cancelTask(TaskId id) =0

Removes task from scheduler.

Parameters

NameTypeDescription
taskIdId number of task to be removed

methcancelTasksabstract

void cancelTasks(Plugin& plugin) =0

Removes all tasks associated with a particular plugin from the scheduler.

Parameters

NameTypeDescription
pluginPlugin&Owner of tasks to be removed

methisRunningabstract

bool isRunning(TaskId id) =0

Check if the task currently running.

Parameters

NameTypeDescription
taskIdThe task to check.

Returns

TypeDescription
boolIf the task is currently running.

methisQueuedabstract

bool isQueued(TaskId id) =0

Check if the task queued to be run later.

Parameters

NameTypeDescription
taskIdThe task to check.

Returns

TypeDescription
boolIf the task is queued to be run.

methgetPendingTasksabstract

std::vector<Task*> getPendingTasks() =0

Returns a vector of all pending tasks.

The ordering of the tasks is NOT related to their order of execution.

Returns

TypeDescription
std::vector<Task*>Pending tasks

classTask

Defined in <endstone/scheduler/task.h>

Represents a task being executed by the scheduler.

Methods

meth~Taskvirtual

~Task() =default

methgetTaskIdabstractconst

TaskId getTaskId() const =0

Returns the taskId for the task.

Returns

TypeDescription
TaskIdTask id number

methgetOwnerabstractconst

Plugin* getOwner() const =0

Returns the Plugin that owns this task.

Returns

TypeDescription
Plugin*The Plugin that owns the task

methisSyncabstractconst

bool isSync() const =0

Returns true if the Task is a sync task.

Returns

TypeDescription
booltrue if the task is run by server thread

methisCancelledabstractconst

bool isCancelled() const =0

Returns true if this task has been cancelled.

Returns

TypeDescription
booltrue if the task has been cancelled

methcancelabstract

void cancel() =0

Attempts to cancel this task.

typeTaskId

On this page