YYC_GroupTask

Extends YYC_Task

constructor

new YYC_GroupTask(_children, _func[, _arg])

Description

A group of tasks executed in parallel. The group task's function is executed when they are all finished.

Arguments

Name Type Description
_children YYC_Task[] An array of tasks executed within the group.
_func func A function executed when all child tasks are finished. It will be passed _arg as the first argument and the task instance as the second.
_arg any An optional argument for the task function. Defaults to undefined.

Properties

Name Description
Children An array of child tasks.

Example

Following example creates a group of tasks which sleep for 1,2 and 3 seconds and then show a message. When they are all finished, the group task itself sleeps for another 1 second and then shows a message. Without YYC Boost this would take 7 seconds in total, as the tasks cannot be executed in parallel. With YYC Boost and at least 3 threads (one for each job within the group) this takes 4 seconds.

// Create event
var _sleepTask = function (_arg) {
    var _ms = _arg[0];
    var _message = _arg[1];
    var _t = current_time;
    while (current_time - _t < _ms) {}
    show_debug_message(_message);
};

new YYC_GroupTask([
    new YYC_Task(_sleepTask, [1000, "Task 1 done!"]),
    new YYC_Task(_sleepTask, [2000, "Task 2 done!"]),
    new YYC_Task(_sleepTask, [3000, "Task 3 done!"]),
], _sleepTask, [1000, "Group 1 done!"]).Run();

// Step event
if (!yyc_is_boost())
{
    yyc_tasks_update();
}

See also

YYC_Task

Do you find this page helpful?

Copyright © 2021, Patrik Kraif. Built on October 14, 2021 using GMDoc.