# Timeout

## MSK.Timeout.Set

Set a new asyncron timeout

<mark style="color:red;">**Parameters**</mark>\
**miliseconds** - `number` - Time to wait\
**cb** - `function` - Callback Function

```lua
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

<mark style="color:red;">**Parameters**</mark>\
**timeout** - `number` - Timeout ID

```lua
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**](https://overextended.dev/ox_lib/Modules/WaitFor/Shared) **for this amazing function!**

<mark style="color:red;">**Parameters**</mark>\
**miliseconds** - `number` - Time to wait\
**cb** - `function` - Callback Function\
**errorMessage** - `string` - Message on error

<mark style="color:green;">**Returns**</mark>\
**value** - `?` - The given value

```lua
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)
```
