feat(init): implement interval

This is different from the one implemented in Ox ESX.
This commit is contained in:
Linden
2021-11-25 00:56:07 +11:00
parent e9f64c53e6
commit 9adbccd2f8

View File

@@ -35,6 +35,37 @@ function import(file)
return IMPORTS[file] return IMPORTS[file]
end end
-----------------------------------------------------------------------------------------------
-- Global functions
-----------------------------------------------------------------------------------------------
--- Dream of a world where this PR gets accepted.
--- ```lua
--- SetInterval(callback: function, timer: number)
--- ```
SetInterval = setmetatable({currentId = 0}, {
__call = function(self, callback, timer)
local id = self.currentId + 1
self.currentId = id
self[id] = timer or 0
CreateThread(function()
repeat
local interval = self[id]
Wait(interval)
callback(interval)
until interval == -1
self[id] = nil
end)
return id
end
})
function ClearInterval(id)
if SetInterval[id] then
SetInterval[id] = -1
end
end
-- pe-lualib -- pe-lualib
-- Copyright (C) 2021 Linden <https://github.com/thelindat> -- Copyright (C) 2021 Linden <https://github.com/thelindat>