- Scheduler Options
- Forcing Task Completion
- Code Examples
In CET, task schedulers are the objects which own, manage, and run tasks. They're also responsible for managing priority, and for sleeping and waking tasks. Task schedulers are a part of the main loop of CET.
In CET, there are two different task schedulers available for general use. Both schedulers are inside the
tasks.cm file in the
||The idle task scheduler, which runs tasks while no active
||The priority task scheduler, which should only be used when tasks need to run while an
Adding a Task to the Scheduler
.add(..) method on task schedulers adds a task to the scheduler. The method takes a descriptive name and a function with the task function signature as required parameters.
idleTasks.add("Name of task", function taskFn);
||Yes||A descriptive name given to the task.|
||Yes||A callback function to run for this task.|
||No||An object to be passed to the task when it executes.|
||No||A priority given to this task.|
||No||Sets the sleep value of the task.|
||No||This task should sleep before executing for the first time.|
||No||Allow this task to run while modals are open.|
||No||Add task tracing. (for debug use).|
||No||Block this task from the scheduler if the argument isn't unique.|
||No||Intended for internal use.|
Tasks inserted into to the scheduler may include a priority in the
add(..) method which informs the scheduler of the tasks' relative importance. A task with too high a priority will cause a task to run ahead of more important tasks. A task with too low of a priority may cause a task to not run as often as needed.
|Task Type||Priority Recommendation||Example|
|Tasks whose results aren't relevant nor observable to the user.||100 through 500||Cache Maintenance, Server Status Checking|
|Tasks whose results are observable to the user.||10 through 100||Loading Domains from File, Checking Status of a User Operation|
A task which requests to sleep will be ignored by the scheduler and not run for a minimum period of time set by a
timespan in the
sleep parameter on the
add(..) method. This is useful for tasks that need to run periodically, such as a task that checks the status of a network operation. A task never sleeps unless it explicitly requests to do so. Tasks should only sleep for durations greater than one second.
Forcing Task Completion
finish(..) methods on the scheduler force a task to complete. This is useful when a user requires a task's results right away. An example of this would be when a user wishes to use data from a file which is being loaded by a task. Upon the users request for the data, the task should be forced to finish.
Tasks may fail to finish if they are incorrectly written, or leave CET unresponsive longer than expected. If a task fails to finish, the finish method will return
false. If a task finishes, the finish method will return
- Adding a task to the scheduler.
idleTasks.add("Example Task", function exampleTask, arg=9999);
- Retrieving a task from the scheduler.
Task task = idleTasks.get("Example Task");
- Finishing a task by name.
bool taskCompleted = idleTasks.finish("Example Task");
- Finishing a task by function.
- Finishing a task by function and argument.
idleTasks.finish(function exampleTask, myArg);