mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(init): implement interval
This is different from the one implemented in Ox ESX.
This commit is contained in:
31
init.lua
31
init.lua
@@ -35,6 +35,37 @@ function import(file)
|
||||
return IMPORTS[file]
|
||||
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
|
||||
-- Copyright (C) 2021 Linden <https://github.com/thelindat>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user