diff options
Diffstat (limited to 'unit_tests/scripts/coro/join_suspended.lua')
-rw-r--r-- | unit_tests/scripts/coro/join_suspended.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/unit_tests/scripts/coro/join_suspended.lua b/unit_tests/scripts/coro/join_suspended.lua new file mode 100644 index 0000000..33be406 --- /dev/null +++ b/unit_tests/scripts/coro/join_suspended.lua | |||
@@ -0,0 +1,24 @@ | |||
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 join a yielded lane, the lane aborts | ||
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 | -- join the lane. since it will reach a yield point, it unblocks and ends. last yielded values are returned normally | ||
21 | local b, r = h:join(0.5) | ||
22 | local s = h.status | ||
23 | assert(s == "done" and b == true and r == "world", "got " .. s .. " " .. tostring(b) .. " " .. tostring(r)) | ||
24 | end | ||