Reference for the Mosaic class Core::TaskQueue

Core::TaskQueue
OnDone
CancelTask()
GetCurrentTask()
ScheduleTask()

The class Core::TaskQueue provides a simple task scheduler component. The component implements functionality to register, manage and perform tasks. A task can be e.g. an animated transition between two GUI components. With the task queue, several independent transitions (and another operations) can be executed strictly one after another.

Usually the tasks are executed in the order in which they were previously added to the queue (the order in which they are scheduled). The queue takes care that at the same time only one task is executed. This task is called the 'current' task. As soon as the current task is completed, the queue activates the next available task.

A single task is represented by an instance of a class derived from Core::Task. To schedule a task, create an instance of the task class and call the method ScheduleTask() with the task as parameter.

With the method CancelTask() you can remove a previously scheduled task from the queue again or if the task is already running, stop it and let the queue continue with the next task.

The method GetCurrentTask() is useful to determine which task is currently in progress by the affected queue.

It is essential to understand, that the entire 'task' functionality has nothing to do with multi-threading or multi-tasking features known from operating systems. Applications developed with Chora are limited to a single-thread environment. There is no real background thread activity. Accordingly your implementation of a task should behave cooperatively. A well designed task should perform its job quickly, use timers or effects to delay execution and when the job is done inform the queue about its completion.

method void CancelTask
(
arg Core::Task aTask
);

The method CancelTask() allows the application to remove a previously registered task from the task queue. The affected task is determined by the parameter aTask.

If the affected task is currently executed, the task is notified to immediately finalize its work. Afterwards the queue starts the next available task. The method will throw an error if you try to cancel a task not belonging to this queue.

method Core::Task GetCurrentTask();

The method GetCurrentTask() returns the task which is currently in progress or 'null' if no task is executed at the time.

property slot OnDone = null;

The property 'OnDone' can refer to a slot method to signal as soon as the queue has terminated the last task and there is no more tasks pending for their execution.

method void ScheduleTask
(
arg Core::Task aTask,
arg bool aWithPriority
);

The method ScheduleTask() registers the task passed in the parameter aTask for later execution.

The tasks are executed in the order in which they have been previously scheduled. If the parameter aWithPriority is false, the new task will be arranged at the end of the list with waiting tasks. If the parameter is true, the task is enqueued in front of all waiting tasks.

The method will throw an error if you try to schedule the same task twice.