Tasks
A help page showing you how to work with tasks
Wait...what is that?
Tasks are exercises (or tasks) that can be executed in parts / scheduled / repeated. They can be used for lot's of things such as mysql pings, presence updates etc.
They are pretty simple written but also very effective which means that you can plan your source execution better.
How to create a Task?
The structure of tasks always stays the same, for the options below, we're only changing the parent constructor, you gonna see when reading.
Basic structure:
TaskManager::getInstance()->submitTask(new class extends Task {
public function __construct() {
parent::__construct($delay, $repeating, $interval);
}
public function onRun(int $seconds) {
// You're task contents here
}
});In the instructions below, the variables $delay, $repeating, $interval you can find on line 3 are going to be changed.
Delayed Task
If you simply want to delay a task just replace line 3 with this content:
You have to change `$delay` by the time in seconds you want the task to be delayed.
A delay of 2 seconds would lead the task to wait 2 seconds until it's getting executed.
Repeating Task
A repeating task is a task is repeating itself until it gets stopped.
You have to replace line 3 with this content:
The first two parameters (0 and true) can stay like how they are, you only have to change the third parameter $interval to any interger that is greater than 0. It stands for the time in seconds the task waits until it's repeating itself.
An interval of 2 seconds would lead the task to wait 2 seconds between every execute
Delayed Repeating Task
If you want to combine the two kinds of tasks above, you have to replace line 3 with this content:
The second parameter can stay like how it is (true), you only have to change $delay and $interval to values explained in the instructions above.
Examples
A basic delayed Task
A repeating presence updater
Last updated