Introduction
The CET task scheduling system allows developers to execute code asynchronously in CET. This code runs using idle time available on the main thread. Use of this system can improve the performance of an extension by offloading non-critical tasks to run at a slower pace. This allows the user to continue to use CET without interruptions.
Tasks and Schedulers
The system consists of two main components: Tasks and Task Schedulers. Tasks, which are the actual functions that run in the background, and schedulers, which are the executors of those tasks. Tasks belong to a scheduler, and the scheduler runs the tasks. The scheduler of a task will also sleep or end that task when requested.
When To Use the Task Schedulers
The task schedulers may be useful when a result isn't critical to the user experience. For example, a function that checks the status of a network operation isn't required to complete for the user to continue using CET. In this case, a task could check for the status of the operation while the user continues to work. The task system should never be used in a case where a user requires a result to keep using CET.
Time Insensitive Results
When a result of a task is not required by a set time, the task system allows deferring completion until a later time. An example of this would be trimming a cache, where the end result of the operation is in no way required by the user.
Lazy Results
If a time insensitive result can become required due to user interaction, tasks can be forced to complete. With this, developers can take advantage of idle CPU time, while still providing results when required by the user. An example of this would be a function that pre-loads domains for a snapper. If the user inserts the snapper, the tasks can be forced to finish.
Periodic Activity
When execution of code needs to happen on a periodic basis, sleeping tasks can be a good solution. An example of this would be checking for the status of an ongoing external operation every 30 seconds. Tasks should not be used for periods of less than one second.
Task Manager
When CET is in developer mode, the debug dropdown in the menu bar has an option for Task Manager underneath the Monitor Toolbox section. This tool allows viewing the current state of all scheduled tasks.
Comments
0 comments
Article is closed for comments.