await(task, ...) iterator

Wait for the task to terminate, suspending execution and allowing other tasks to run during this time.

Unlike async(), await() will block execution flow even if the task calls the sleep() function.

Parameters

task

A function or a Task object instance to wait for. If a function is supplied, a new task instance is transparently created and started.

Other provided optional arguments are used as function arguments when the Task is started.

Return value

This function returns the Task return values.

Example

-- Counts from 5 to 10 print (await (function (from, to) local i = from while i <= to do sleep(500) print(i) i = i +1 end -- The Task will return the string "Done !" return "Done !" end, 5, 10))