async.mutex
Shared
Runs a function in a new async thread, as async.thread does, but does not start while another thread started from the same line of code, with the same key, is still running.
any async.mutex(function func [, any key = nil])
Parameters
| Name | Type | Description |
|---|---|---|
| func | function | The function the thread runs. |
| key | any | A value that keeps the same line's locks apart, such as a player. It is turned into text as tostring does.default nil |
Returns
The thread, or false if a thread from the same line and the same key has not ended yet.
Example
addCommandHandler("save", function(player)
local started = async.mutex(function()
async.wait(2000)
outputDebugString(getPlayerName(player) .. " saved")
end, player)
if not started then
outputDebugString(getPlayerName(player) .. " is already saving")
end
end)