Task.status readonly property
The Task.status returns the current state of the Task, as a string. Possible values are :
- "created" : the Task has just been created, and has not started.
- "running" : the Task is currently running.
- "sleeping" : the Task is sleeping (ie has called the global sleep() function).
- "waiting" : the Task is waiting for another Task to terminate.
- "terminated" : the Task has terminated its execution.
Example
-- print a message after a delay (in seconds)
local function print_after(delay, message)
sleep(delay*1000)
print(message)
end
-- print "Hello" after 1 second
local task1 = sys.Task(print_after)
print("Task1 is "..task1.status)
task1(1, "Hello")
-- print "Hello" after 2 seconds
local task2 = sys.Task(print_after)
print("Task2 is "..task2.status)
task2(1, "Hello")
await(task1)
print("Task1 is "..task1.status)
await(task2)
print("Task2 is "..task2.status)
-- wait for all tasks to finish before exit
waitall()