From 4bb69c15e8ef3e4df75a488d88dd0bf699180eb2 Mon Sep 17 00:00:00 2001 From: Ilias Rbayti <63159154+Kenshiin13@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:26:39 +0100 Subject: [PATCH] refactor(cron/server/main): Add type annotations --- [core]/cron/server/main.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/[core]/cron/server/main.lua b/[core]/cron/server/main.lua index 4d2b650f..76b8915b 100644 --- a/[core]/cron/server/main.lua +++ b/[core]/cron/server/main.lua @@ -1,6 +1,16 @@ -local Jobs = {} -local LastTime = nil +---@class CronJob +---@field h number +---@field m number +---@field cb function +---@type CronJob[] +local Jobs = {} +---@type number|false +local LastTime = false + +---@param h number +---@param m number +---@param cb function function RunAt(h, m, cb) Jobs[#Jobs + 1] = { h = h, @@ -9,10 +19,12 @@ function RunAt(h, m, cb) } end +---@return number function GetUnixTimestamp() return os.time() end +---@param time number function OnTime(time) for i = 1, #Jobs, 1 do local scheduledTimestamp = os.time({ @@ -31,6 +43,7 @@ function OnTime(time) end end +---@return nil function Tick() local time = GetUnixTimestamp() @@ -43,7 +56,6 @@ function Tick() end LastTime = GetUnixTimestamp() - Tick() AddEventHandler("cron:runAt", function(h, m, cb)