一旦设置,如何访问计时器的值?

时间:2013-08-12 02:31:55

标签: timer rebol rebol3 r3-gui

鉴于下面的R3-GUI代码,有没有办法访问计时器剩余多少时间?计时器ID由set-timer返回,但我不确定我能用它做什么吗?

set-timer [print "done"] 60

换句话说,我在假代码示例中寻找的是什么:

>> get-timer/time-remaining timer-id
== 0:0:21

1 个答案:

答案 0 :(得分:0)

通过查看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

如果计时器结束,do-events会清除它。如果没有运行事件,那么即使在时间用完之后计时器也会停留。