- Documentation
- Shared functions
- getTaskStatus
Function
getTaskStatus
Returns the state of a task from async: "running" (waiting or working), "done" (finished) or "failed" (error). After the state it returns the values returned by the task function or, for "failed", the error message.
Syntax
string, ... getTaskStatus(task task)Arguments
tasktask- A task from
async.
Returns
The state and the task's results.
Example
local task = async(function()
sleep(500)
return 42
end)
setTimer(function()
print(getTaskStatus(task)) -- done 42
end, 1000, 1)
See also
asyncRuns a function as a task (coroutine). The code in the task runs immediately until its first wait (sleep,await,waitForEvent). Then it yields and the server and the game keep running. When the wait is over, the task continues from where it stopped. This lets you write steps spread over time (a countdown, a database query, an HTTP response, waiting for a player) one after another, without nested callbacks and timers.isTaskChecks whether a value is a task returned byasync.