M MY Multiplayer: Wiki
Side
Kind

async.promise

Shared

Runs handler(resolve, reject) in a new thread and makes the current thread wait until it calls resolve or reject. Meant for waiting on a function that answers through a callback.

any async.promise(function handler)

Parameters

NameTypeDescription
handlerfunctionA function that receives resolve and reject. Only the first call of either counts.

Returns

The values passed to resolve. Only works inside an async thread. Outside one, it logs an error and returns false.

Example

local function delay(ms)
    return async.promise(function(resolve)
        setTimer(resolve, ms, 1, "done")
    end)
end

async.thread(function()
    local result = delay(500)
    outputDebugString(result)
end)
Notereject(value), or an error inside handler, becomes an error in the waiting thread. Wrap it in pcall to handle it.

See also