From 7c040842b09f952e98187b65019cd55176a5ddf4 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 4 Jul 2025 09:18:19 +0200 Subject: Split coro tests in several scripts --- unit_tests/scripts/_utils54.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 unit_tests/scripts/_utils54.lua (limited to 'unit_tests/scripts/_utils54.lua') 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 @@ +local utils = require "_utils" + +-- expand _utils module with Lua5.4 specific stuff + +-- a lane body that yields stuff +utils.yielder_with_to_be_closed = function(out_linda_, wait_) + local fixture = assert(require "fixture") + -- here is a to-be-closed variable that, when closed, sends "Closed!" in the "out" slot of the provided linda + local t = setmetatable( + { text = "Closed!" }, { + __close = function(self, err) + if wait_ then + fixture.block_for(wait_) + end + out_linda_:send("out", self.text) + end + } + ) + -- yield forever, but be cancel-friendly + local n = 1 + while true do + coroutine.yield("I yield!", n) + if cancel_test and cancel_test() then -- cancel_test does not exist when run immediately (not in a Lane) + return "I am cancelled" + end + n = n + 1 + end +end + +return utils -- cgit v1.2.3-55-g6feb