M MY Multiplayer: Wiki
Side
Kind

async.thread

Shared

Runs a function in a new async thread, right away. The call returns when the function ends or first pauses, as with async.wait.

any async.thread(function func [, function callback = nil])

Parameters

NameTypeDescription
funcfunctionThe function the thread runs.
callbackfunctionCalled with the values func returned, when it ends without an error.default nil

Returns

The thread (a Lua coroutine), to use with async.cancel and async.status.

An error inside the thread is logged with its stack trace. A resource's threads end when it stops.

Example

async.thread(function()
    for i = 3, 1, -1 do
        outputDebugString("starting in " .. i)
        async.wait(1000)
    end
    return "go"
end, function(result)
    outputDebugString(result)
end)

See also