pull/2/head
jaysunxiao 2021-10-03 17:41:16 +08:00
parent c206823b30
commit 324f7acafe
2 changed files with 24 additions and 0 deletions

View File

@ -9,12 +9,21 @@ const CollectionUtils = preload("res://zfoo/util/CollectionUtils.gd")
const schedulerMap: Dictionary = {} const schedulerMap: Dictionary = {}
# 固定延迟执行的任务delay默认为毫秒
static func schedule(runnable: Runnable, delay: int) -> void: static func schedule(runnable: Runnable, delay: int) -> void:
var triggerTimestamp = TimeUtils.currentTimeMillis() + delay var triggerTimestamp = TimeUtils.currentTimeMillis() + delay
var definition = SchedulerDefinition.new(runnable, delay, triggerTimestamp, false) var definition = SchedulerDefinition.new(runnable, delay, triggerTimestamp, false)
schedulerMap[definition] = null schedulerMap[definition] = null
# 不断执行的周期循环任务delay默认为毫秒
static func scheduleAtFixRate(runnable: Runnable, delay: int) -> void:
var triggerTimestamp = TimeUtils.currentTimeMillis() + delay
var definition = SchedulerDefinition.new(runnable, delay, triggerTimestamp, false)
schedulerMap[definition] = null
static func triggerPerSecond() -> void: static func triggerPerSecond() -> void:
var timestamp = TimeUtils.currentTimeMillis() var timestamp = TimeUtils.currentTimeMillis()

View File

@ -1,5 +1,20 @@
extends Object extends Object
# 一秒钟对应的纳秒数
const NANO_PER_SECOND: int = 1_000_000_000
# 一秒钟对应的毫秒数
const MILLIS_PER_SECOND: int = 1 * 1000
# 一分钟对应的毫秒数
const MILLIS_PER_MINUTE = 1 * 60 * MILLIS_PER_SECOND
# 一个小时对应的毫秒数
const MILLIS_PER_HOUR = 1 * 60 * MILLIS_PER_MINUTE
# 一天对应的毫秒数
const MILLIS_PER_DAY = 1 * 24 * MILLIS_PER_HOUR
# 一周对应的毫秒数
const MILLIS_PER_WEEK = 1 * 7 * MILLIS_PER_HOUR
const timestamp = [0] const timestamp = [0]