aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts/coro/yielding_function.lua
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/scripts/coro/yielding_function.lua')
-rw-r--r--unit_tests/scripts/coro/yielding_function.lua34
1 files changed, 13 insertions, 21 deletions
diff --git a/unit_tests/scripts/coro/yielding_function.lua b/unit_tests/scripts/coro/yielding_function.lua
index 636f094..6518d1f 100644
--- a/unit_tests/scripts/coro/yielding_function.lua
+++ b/unit_tests/scripts/coro/yielding_function.lua
@@ -23,7 +23,7 @@ end
23-------------------------------------------------------------------------------------------------- 23--------------------------------------------------------------------------------------------------
24-- TEST: if we start a non-coroutine lane with a yielding function, we should get an error, right? 24-- TEST: if we start a non-coroutine lane with a yielding function, we should get an error, right?
25-------------------------------------------------------------------------------------------------- 25--------------------------------------------------------------------------------------------------
26if false then 26if true then
27 local fun_g = lanes.gen("*", { name = 'auto' }, yielder) 27 local fun_g = lanes.gen("*", { name = 'auto' }, yielder)
28 local h = fun_g("hello", "world", "!") 28 local h = fun_g("hello", "world", "!")
29 local err, status, stack = h:join() 29 local err, status, stack = h:join()
@@ -48,7 +48,7 @@ local coro_g = lanes.coro("*", {name = "auto"}, yielder)
48------------------------------------------------------------------------------------------------- 48-------------------------------------------------------------------------------------------------
49-- TEST: we can resume as many times as the lane yields, then read the returned value on indexing 49-- TEST: we can resume as many times as the lane yields, then read the returned value on indexing
50------------------------------------------------------------------------------------------------- 50-------------------------------------------------------------------------------------------------
51if false then 51if true then
52 -- launch coroutine lane 52 -- launch coroutine lane
53 local h = coro_g("hello", "world", "!") 53 local h = coro_g("hello", "world", "!")
54 -- read the yielded values, sending back the expected index 54 -- read the yielded values, sending back the expected index
@@ -63,7 +63,7 @@ end
63--------------------------------------------------------------------------------------------- 63---------------------------------------------------------------------------------------------
64-- TEST: we can resume as many times as the lane yields, then read the returned value on join 64-- TEST: we can resume as many times as the lane yields, then read the returned value on join
65--------------------------------------------------------------------------------------------- 65---------------------------------------------------------------------------------------------
66if false then 66if true then
67 -- launch coroutine lane 67 -- launch coroutine lane
68 local h = coro_g("hello", "world", "!") 68 local h = coro_g("hello", "world", "!")
69 -- read the yielded values, sending back the expected index 69 -- read the yielded values, sending back the expected index
@@ -75,9 +75,9 @@ if false then
75 assert(h.status == "done" and s == true and r == "bye!") 75 assert(h.status == "done" and s == true and r == "bye!")
76end 76end
77 77
78--------------------------------------------------------------------------------------------------- 78---------------------------------------------------
79-- TEST: if we join a yielded lane, we get a timeout, and we can resume as if we didn't try to join 79-- TEST: if we join a yielded lane, the lane aborts
80--------------------------------------------------------------------------------------------------- 80---------------------------------------------------
81if true then 81if true then
82 -- launch coroutine lane 82 -- launch coroutine lane
83 local h = coro_g("hello", "world", "!") 83 local h = coro_g("hello", "world", "!")
@@ -89,10 +89,10 @@ if true then
89 assert(s == "done" and b == true and r == "world", "got " .. s .. " " .. tostring(b) .. " " .. tostring(r)) 89 assert(s == "done" and b == true and r == "world", "got " .. s .. " " .. tostring(b) .. " " .. tostring(r))
90end 90end
91 91
92----------------------------------------------------------------------- 92-------------------------------------------------------------------------
93-- TEST: if we index yielded lane, we should get the last yielded value 93-- TEST: if we index a yielded lane, we should get the last yielded value
94----------------------------------------------------------------------- 94-------------------------------------------------------------------------
95if false then 95if true then
96 -- launch coroutine lane 96 -- launch coroutine lane
97 local h = coro_g("hello", "world", "!") 97 local h = coro_g("hello", "world", "!")
98 -- read the first yielded value, sending back the expected index 98 -- read the first yielded value, sending back the expected index
@@ -102,15 +102,7 @@ if false then
102 local r2 = h[1] 102 local r2 = h[1]
103 local r3 = h[1] 103 local r3 = h[1]
104 assert(r1 == "world" and r2 == "world" and r3 == "world", "got " .. r1 .. " " .. r2 .. " " .. r3) 104 assert(r1 == "world" and r2 == "world" and r3 == "world", "got " .. r1 .. " " .. r2 .. " " .. r3)
105 assert(h:resume(2) == "world") 105 -- once the lane was indexed, it is no longer resumable (just like after join)
106 106 local b, e = pcall(h.resume, h, 2)
107 -- THERE IS AN INCONSISTENCY: h:resume pulls the yielded values directly out of the lane's stack 107 assert(b == false and e == "cannot resume non-suspended coroutine Lane")
108 -- but h[n] removes them and stores them in the internal values storage table
109 -- TODO: so we need to decide: should indexing a yielded lane work like resume()?
110 assert(h:resume(3) == "!")
111end 108end
112
113-------------------------------------------------------------------------------------
114-- TEST: if we close yielded lane, we can join it and get the last yielded values out
115-------------------------------------------------------------------------------------
116-- TODO: we need to implement lane:close() for that!