waitall([Task1, Task2, ...])function
Suspend the current execution flow until all running tasks (or only the specified ones) have been terminated.
Parameters
[Task1, Task2, ...]
Optional Task
objects to wait for. If no Task is provided, the function will wait for all running tasks to terminate.Return value
This function returns no value when waiting for all tasks, or atable containing the results of the completed tasks. Each entry is a table with the returned values of the corresponding Task in order
Example
-- Create 2 tasks that return multiple values
local t1 = sys.Task(function()
sleep(500)
return "alpha", 1
end)
local t2 = sys.Task(function()
sleep(800)
return "beta", 2
end)
-- start tasks
t1(); t2()
-- Each entry in results is a table with the returned values of the corresponding Task
local results = waitall(t1, t2)
-- print using table.unpack to expand each Task's return values
for i, res in ipairs(results) do
local value1, value2 = table.unpack(res)
print(("Task %d results: %s, %s"):format(i, value1, value2))
end