aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts/coro/regular_function.lua
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-06-26 09:18:54 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-06-26 09:18:54 +0200
commitd7d756e30680bcff036118b47ac45b740e020ea2 (patch)
tree3e2a26409154760d66092e6e04a9fcb4ad4ed02a /unit_tests/scripts/coro/regular_function.lua
parent4f5fa626c0279f5aefac477a29702c43a6754c5a (diff)
downloadlanes-d7d756e30680bcff036118b47ac45b740e020ea2.tar.gz
lanes-d7d756e30680bcff036118b47ac45b740e020ea2.tar.bz2
lanes-d7d756e30680bcff036118b47ac45b740e020ea2.zip
Preparation for lane:close() and correct to-be-closed variables
* lane:join() can no longer be used to read yielded values * same with lane indexing * stub for lane:close(), similar to coroutine.close() (not implemented yet) * preparing tests for to-be-closed variables in yielded coroutine lanes * yielded lanes unlock and terminate properly at Lanes shutdown
Diffstat (limited to 'unit_tests/scripts/coro/regular_function.lua')
-rw-r--r--unit_tests/scripts/coro/regular_function.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/unit_tests/scripts/coro/regular_function.lua b/unit_tests/scripts/coro/regular_function.lua
new file mode 100644
index 0000000..09aa3b7
--- /dev/null
+++ b/unit_tests/scripts/coro/regular_function.lua
@@ -0,0 +1,38 @@
1local lanes = require "lanes".configure()
2
3local utils = lanes.require "_utils"
4local PRINT = utils.MAKE_PRINT()
5
6-- a lane body that just returns some value
7local returner = function(msg_)
8 local utils = lanes.require "_utils"
9 local PRINT = utils.MAKE_PRINT()
10 PRINT "In lane"
11 assert(msg_ == "hi")
12 return "bye"
13end
14
15-- a function that returns some value can run in a coroutine
16if true then
17 -- the generator
18 local g = lanes.coro("*", {name = "auto"}, returner)
19
20 -- launch lane
21 local h = g("hi")
22
23 local r = h[1]
24 assert(r == "bye")
25end
26
27-- can't resume a coro after the lane body has returned
28if true then
29 -- the generator
30 local g = lanes.coro("*", {name = "auto"}, returner)
31
32 -- launch lane
33 local h = g("hi")
34
35 -- resuming a lane that terminated execution should raise an error
36 local b, e = pcall(h.resume, h)
37 assert(b == false and type(e) == "string")
38end