mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
27 lines
631 B
Lua
27 lines
631 B
Lua
--
|
|
-- Timer Callback Dispatcher
|
|
--
|
|
|
|
local tcallbackdsp = {}
|
|
|
|
local registry = {}
|
|
|
|
-- request a function to be called after the specified time
|
|
---@param time number seconds
|
|
---@param f function callback function
|
|
function tcallbackdsp.dispatch(time, f)
|
|
---@diagnostic disable-next-line: undefined-field
|
|
registry[os.startTimer(time)] = { callback = f }
|
|
end
|
|
|
|
-- lookup a timer event and execute the callback if found
|
|
---@param event integer timer event timer ID
|
|
function tcallbackdsp.handle(event)
|
|
if registry[event] ~= nil then
|
|
registry[event].callback()
|
|
registry[event] = nil
|
|
end
|
|
end
|
|
|
|
return tcallbackdsp
|