File: timertest.lua

package info (click to toggle)
lua-event 0.4.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: ansic: 741; makefile: 40; sh: 1
file content (26 lines) | stat: -rw-r--r-- 562 bytes parent folder | download | duplicates (6)
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
local core = require("luaevent.core")

c = core.new()
local f = 100
local function createEvent()
	return c:addevent(nil, core.EV_TIMEOUT, function(ev)
		io.write(".." .. f)
		f = f - 1
		if f < 0 then
			return -1
		end
		collectgarbage()
	end, 0.01)
end
ev = createEvent()
print("TESTING Garbage-collect-safe version")
c:loop()
assert(f < 0, "DID NOT FINISH LOOPING")
io.write("\n")
print("TESTING Garbage-collect unsafe version")
f = 100
createEvent()
c:loop()
assert(f >= 0, "Did not perform expected collection")
io.write("\n")
print("Completed both tests")