diff options
Diffstat (limited to 'unit_tests/scripts/coro/index_suspended.lua')
-rw-r--r-- | unit_tests/scripts/coro/index_suspended.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/unit_tests/scripts/coro/index_suspended.lua b/unit_tests/scripts/coro/index_suspended.lua new file mode 100644 index 0000000..2cd8c28 --- /dev/null +++ b/unit_tests/scripts/coro/index_suspended.lua | |||
@@ -0,0 +1,28 @@ | |||
1 | local lanes = require "lanes" | ||
2 | |||
3 | local fixture = require "fixture" | ||
4 | lanes.finally(fixture.throwing_finalizer) | ||
5 | |||
6 | local utils = lanes.require "_utils" | ||
7 | local PRINT = utils.MAKE_PRINT() | ||
8 | |||
9 | -- the coroutine generator | ||
10 | local coro_g = lanes.coro("*", {name = "auto"}, utils.yield_one_by_one) | ||
11 | |||
12 | ------------------------------------------------------------------------- | ||
13 | -- TEST: if we index a yielded lane, we should get the last yielded value | ||
14 | ------------------------------------------------------------------------- | ||
15 | if true then | ||
16 | -- launch coroutine lane | ||
17 | local h = coro_g("hello", "world", "!") | ||
18 | -- read the first yielded value, sending back the expected index | ||
19 | assert(h:resume(1) == "hello") | ||
20 | -- indexing multiple times gives back the same us the same yielded value | ||
21 | local r1 = h[1] | ||
22 | local r2 = h[1] | ||
23 | local r3 = h[1] | ||
24 | assert(r1 == "world" and r2 == "world" and r3 == "world", "got " .. r1 .. " " .. r2 .. " " .. r3) | ||
25 | -- once the lane was indexed, it is no longer resumable (just like after join) | ||
26 | local b, e = pcall(h.resume, h, 2) | ||
27 | assert(b == false and e == "cannot resume non-suspended coroutine Lane") | ||
28 | end | ||