This commit is contained in:
lenheart
2024-10-27 15:32:44 +08:00
parent e82c5ceee3
commit 6c71c79563
21 changed files with 846 additions and 253 deletions

View File

@@ -17,9 +17,13 @@ class Timer {
Cb_timer_dispatch_Func.rawset("__System__Timer__Event", Update.bindenv(this));
}
function ClockTime() {
return Sq_GetTimestampString().slice(-10).tointeger();
}
//检测延时任务
function CheckTimeOut() {
local Node = Wait_Exec_Tree.pop();
local Node = Wait_Exec_Tree.GetPop();
if (!Node) {
return;
}
@@ -27,11 +31,13 @@ class Timer {
local Info = Node.Info;
//执行时间
local exec_time = Node.time;
//如果没到执行时间,放回去,等待下次扫描
if (clock() <= exec_time) {
Wait_Exec_Tree.insert(exec_time, Node.Info);
//如果没到执行时间,就不管
if (ClockTime() <= exec_time) {
return;
}
//该执行了从树中删除这个元素
Wait_Exec_Tree.pop();
//函数
local func = Info[0];
//参数
@@ -47,10 +53,9 @@ class Timer {
target_arg_list.push(vargv[i]);
}
//当前时间戳,单位:秒
local time_sec = clock();
local time_sec = ClockTime();
//计算下一次执行的时间
local exec_time_sec = time_sec + (delay_time / 1000.0).tofloat();
local exec_time_sec = time_sec + delay_time;
//设置下一次执行
local func_info = [];
@@ -62,7 +67,7 @@ class Timer {
//检测定时任务
function CheckCronTask() {
local Node = Date_Exec_Tree.pop();
local Node = Date_Exec_Tree.GetPop();
if (!Node) {
return;
}
@@ -72,9 +77,10 @@ class Timer {
local exec_time = Node.time;
//如果没到执行时间,放回去,等待下次扫描
if (time() <= exec_time) {
Date_Exec_Tree.insert(exec_time, Node.Info);
// Date_Exec_Tree.insert(exec_time, Node.Info);
return;
}
Date_Exec_Tree.pop();
//函数
local func = Info[0];
//参数
@@ -88,18 +94,6 @@ class Timer {
}
function SetCronTask(target_func, CronString, ...) {
// local parts = split(CronString, "/");
// local minute = parts[0].tointeger();
// local hour = parts[1].tointeger();
// local day = parts[2].tointeger();
// local weekday = parts[3].tointeger();
// local S_minute = minute * 60;
// local S_hour = hour * 60 * 60;
// local S_day = day * 24 * 60 * 60;
// local S_weekday = weekday * 7 * 24 * 60 * 60;
// local AddTimestep = S_minute + S_hour + S_day + S_weekday;
local NowTimestep = time();
//下一次执行的时间