To start a Task, just call it like a function, see Task calling
Task:constructor(func)constructor
The Task constructor returns an asynchronous Task, executing the provided function when started.
Parameters
func
A function that will be executed once the Task is started.
Return value
The constructor returns a new Task instance.Example
-- print a message after a delay (in seconds)
local function print_after(delay, message)
sleep(delay*1000)
print(message)
end
-- creates a Task to print "Hello" after 1 second, and starts it
local task1 = sys.Task(print_after)
task1(1, "Hello")
-- creates a Task to print "Hello" after 1 second, and starts it
local task2 = sys.Task(print_after)
task2(1, "Hello")
-- wait for all tasks to finish before exit
waitall()