Timeout

MSK.Timeout.Set

Set a new asyncron timeout

Parameters miliseconds - number - Time to wait cb - function - Callback Function

timeout = MSK.Timeout.Set(miliseconds, function(data)
    print(data) -- Output: 'Hello World'
end, 'Hello World')

-- You can also use:
timeout = MSK.Timeout(miliseconds, function(data)
    print(data) -- Output: 'Hello World'
end, 'Hello World')

-- As an Export:
local timeout = exports.msk_core:SetTimeout(miliseconds, cb)

MSK.Timeout.Clear

Clears the given timeout

Parameters timeout - number - Timeout ID

MSK.Timeout.Clear(timeout)

-- As an Export:
exports.msk_core:ClearTimeout(timeout)

MSK.Timeout.Await

Calls a function repeatedly until it receives a non-nil value, or it times out. The function result is then returned.

Thanks to ox_lib for this amazing function!

Parameters miliseconds - number - Time to wait cb - function - Callback Function errorMessage - string - Message on error

Returns value - ? - The given value

local value = MSK.Timeout.Await(5000, function()
    if math.random(0, 1) == 1 then 
        return 'abc' 
    end
end, 'This is an Error Message')

print(value) -- Output: 'abc'

-- As an Export:
local value = exports.msk_core:AwaitTimeout(ms, cb, errorMessage)

Last updated