Task calling
To start a just created Task instance, uses the parenthesis notation, as for function calling.
The provided arguments will be passed to the Task function.
Example
-- Counting concurrently
local console = require "console"
local function count(start, color)
local i = start
while true do
-- sleep for one second
sleep(500)
-- and print the number with the provided color
console.writecolor(color, i, "\n")
i = i + 2
end
end
-- Create 2 Task using the count() function
local task1 = sys.Task(count)
local task2 = sys.Task(count)
-- Start first task starting to count from 1 in blue
task1(1, "blue")
-- Start first task starting to count from 2 in red
task2(2, "red")
-- Wait for all tasks to terminate before the program exits
waitall()