diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 09:18:19 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 09:18:19 +0200 |
| commit | 7c040842b09f952e98187b65019cd55176a5ddf4 (patch) | |
| tree | 0e5c3ac027429ddad0a4a85961eb97381a0f360a /unit_tests/scripts/_utils54.lua | |
| parent | 72d7b36e020fd3f11ec002c110e7340f667d6628 (diff) | |
| download | lanes-7c040842b09f952e98187b65019cd55176a5ddf4.tar.gz lanes-7c040842b09f952e98187b65019cd55176a5ddf4.tar.bz2 lanes-7c040842b09f952e98187b65019cd55176a5ddf4.zip | |
Split coro tests in several scripts
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 | ||
