-
Notifications
You must be signed in to change notification settings - Fork 70
/
corocbk.lua
58 lines (49 loc) · 1.46 KB
/
corocbk.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
--[[--------------------------------------------------------------------------
LGI testsuite, coroutine-targetted callbacks
Copyright (c) 2010, 2011 Pavel Holejsovsky
Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php
--]]--------------------------------------------------------------------------
local coroutine = require 'coroutine'
local lgi = require 'lgi'
local check, checkv = testsuite.check, testsuite.checkv
-- Basic GObject testing
local corocbk = testsuite.group.new('corocbk')
function corocbk.resume_suspd()
local GLib = lgi.GLib
local main_loop = GLib.MainLoop()
local coro = coroutine.create(
function()
coroutine.yield()
coroutine.yield(true)
main_loop:quit()
end)
coroutine.resume(coro)
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, coro)
main_loop:run()
end
function corocbk.resume_init()
local GLib = lgi.GLib
local main_loop = GLib.MainLoop()
local coro = coroutine.create(
function()
coroutine.yield(true)
main_loop:quit()
end)
GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, coro)
main_loop:run()
end
function corocbk.rethrow()
local GLib = lgi.GLib
local main_loop = GLib.MainLoop()
local coro = coroutine.create(
function()
(function()
error('err', 0)
end)()
end)
GLib.idle_add(GLib.PRIORITY_DEFAULT, coro)
local ok, err = pcall(main_loop.run, main_loop)
checkv(ok, false, 'boolean')
checkv(err, 'err', 'string')
end