diff options
Diffstat (limited to 'unit_tests/scripts/_utils54.lua')
-rw-r--r-- | unit_tests/scripts/_utils54.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/unit_tests/scripts/_utils54.lua b/unit_tests/scripts/_utils54.lua new file mode 100644 index 0000000..a511563 --- /dev/null +++ b/unit_tests/scripts/_utils54.lua | |||
@@ -0,0 +1,30 @@ | |||
1 | local utils = require "_utils" | ||
2 | |||
3 | -- expand _utils module with Lua5.4 specific stuff | ||
4 | |||
5 | -- a lane body that yields stuff | ||
6 | utils.yielder_with_to_be_closed = function(out_linda_, wait_) | ||
7 | local fixture = assert(require "fixture") | ||
8 | -- here is a to-be-closed variable that, when closed, sends "Closed!" in the "out" slot of the provided linda | ||
9 | local t <close> = setmetatable( | ||
10 | { text = "Closed!" }, { | ||
11 | __close = function(self, err) | ||
12 | if wait_ then | ||
13 | fixture.block_for(wait_) | ||
14 | end | ||
15 | out_linda_:send("out", self.text) | ||
16 | end | ||
17 | } | ||
18 | ) | ||
19 | -- yield forever, but be cancel-friendly | ||
20 | local n = 1 | ||
21 | while true do | ||
22 | coroutine.yield("I yield!", n) | ||
23 | if cancel_test and cancel_test() then -- cancel_test does not exist when run immediately (not in a Lane) | ||
24 | return "I am cancelled" | ||
25 | end | ||
26 | n = n + 1 | ||
27 | end | ||
28 | end | ||
29 | |||
30 | return utils | ||