M MY Multiplayer: Wiki
Lado
Tipo

async.mutex

Compartilhado

Roda uma função numa thread async nova, como async.thread, mas não começa enquanto outra thread iniciada pela mesma linha do código, com a mesma key, ainda está rodando.

any async.mutex(function func [, any key = nil])

Parâmetros

NomeTipoDescrição
funcfunctionFunção que roda na thread.
keyanyValor que separa as travas da mesma linha, como um jogador. Ele é convertido em texto, como faz tostring.padrão nil

Retorno

A thread, ou false se uma thread da mesma linha e da mesma key ainda não terminou.

Exemplo

addCommandHandler("save", function(player)
    local started = async.mutex(function()
        async.wait(2000)
        outputDebugString(getPlayerName(player) .. " salvou")
    end, player)

    if not started then
        outputDebugString(getPlayerName(player) .. " já está salvando")
    end
end)

Veja também