给定下面的R3-GUI代码,是否有方法访问计时器中剩余的时间?计时器ID由set-timer
返回,但我不确定是否有什么可以用的?
set-timer [print "done"] 60
换句话说,我在一个伪代码示例中寻找的是:
>> get-timer/time-remaining timer-id
== 0:0:21
通过查看set-timer
的来源可以找到答案
>> source set-timer
set-timer: make function! [[
{Calls a function after a specified amount of time. Returns timer ID reference.}
code [block!]
timeout [number! time!]
/repeat "Periodically repeat the function."
/local t id
][
t: now/precise
if number? timeout [timeout: to time! timeout]
sort/skip/compare append guie/timers compose/deep/only [(id: guie/timer-id: guie/timer-id + 1) [
timeout (t + timeout)
rate (all [
repeat
max 0:00 timeout
])
callback (function [] code)
]] 2 2
guie/timeout: true
id
]
]
如果计时器仍在运行,则它将位于guie
对象中。
>> guie/timers
== []
>> set-timer [print "done"] 2
== 5
>> guie/timers
== [5 [
timeout 11-Aug-2013/22:41:13.381-5:00
rate none
callback make function! [[
/local
][print "done"]]
]]
获取日期值如下所示:
second select guie/timers timer-id
>>b: second select guie/timers 5
==11-Aug-2013/22:41:13.381-5:00
>>c: now/time - b/time
== 0:0:55
如果计时器已结束,则执行事件将其清除。如果事件没有运行,那么即使时间用完,计时器也会保留。