-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathmanual-test-external-loop.lua
60 lines (52 loc) · 1.2 KB
/
manual-test-external-loop.lua
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local uv = require('uv')
local function setTimeout(callback, ms)
local timer = uv.new_timer()
timer:start(ms, 0, function()
uv.walk(function(...)
print('uv.walk() in Main Lua', ...)
end)
timer:stop()
timer:close()
callback()
end)
return timer
end
setTimeout(function()
print('Main Lua done')
end, 1000)
local delay = 100
uv.update_time()
local before = uv.now()
local thread = uv.new_thread(function(delay)
local uv = require('uv')
local t1 = uv.thread_self()
uv.sleep(delay)
local t2 = uv.thread_self()
assert(t1:equal(t2))
assert(tostring(t1)==tostring(t2))
_G.print('Runing', uv.thread_self())
assert(_THREAD)
local function setTimeout(callback, ms)
local timer = uv.new_timer()
timer:start(ms, 0, function()
uv.walk(function(...)
print('in thread Lua', ...)
end)
timer:stop()
timer:close()
callback()
end)
return timer
end
setTimeout(function()
print('thread Lua done')
end, 1000)
uv.run()
end,delay)
print('launch thread:', thread)
uv.thread_join(thread)
-- uv.update_time()
-- local elapsed = uv.now() - before
-- assert(elapsed >= delay, "elapsed should be at least delay ")
uv.run()
print('DONE')