1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
local timers = require 'timers'
print('t0:new(10)')
start = os.clock()
t0 = timers.Timer:new(10, function() print('t0 fired at', os.clock() - start) end)
print('t0:isRunning(): ', t0:isRunning())
print('t0:timeUntilCall(): ', t0:timeUntilCall())
print('t0:cancel(): ', t0:cancel())
print('t0:isRunning(): ', t0:isRunning())
print('t0:timeUntilCall(): ', t0:timeUntilCall())
print('t0:cancel(): ', t0:cancel())
print('t1:new(5)')
start = os.clock()
t1 = timers.Timer:new(5, function() print('t1 fired at', os.clock() - start) end)
print('t2:new(2)')
start = os.clock()
t2 = timers.Timer:new(2)
function t2:tick()
print('t2 fired at', os.clock() - start)
end
start = os.clock()
timers.Timer:new(5, 'wait')
print(string.format('Timer(5) waited %f seconds', os.clock() - start))
start = os.clock()
timers.Timer:new(
2,
coroutine.wrap(function()
for i = 1,5 do
print('repeat(2) timer fired at ', os.clock() - start)
coroutine.yield(nil) -- keep running
end
print('repeat(2) timer fired last at ', os.clock() - start)
return true -- stop
end),
true) -- iterate
|