diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-06-05 16:03:22 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-06-05 16:03:22 +0200 |
| commit | bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8 (patch) | |
| tree | 00f6633878b21dda6cad1177d5619a501b4ac0a4 /unit_tests/scripts/lane | |
| parent | f73702bcf4372a149b8b01a512c0e086b1e679e2 (diff) | |
| download | lanes-bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8.tar.gz lanes-bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8.tar.bz2 lanes-bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8.zip | |
Change lane:join() return values
* when no error is raised in the lane, lane:join() now precedes the lane returned values with true
* lane body is no longer forced to return something when used with join()
* adjusted all relevant unit tests accordingly
Diffstat (limited to 'unit_tests/scripts/lane')
| -rw-r--r-- | unit_tests/scripts/lane/tasking_join_test.lua | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/unit_tests/scripts/lane/tasking_join_test.lua b/unit_tests/scripts/lane/tasking_join_test.lua index 2fbce6c..495a709 100644 --- a/unit_tests/scripts/lane/tasking_join_test.lua +++ b/unit_tests/scripts/lane/tasking_join_test.lua | |||
| @@ -30,14 +30,19 @@ end | |||
| 30 | 30 | ||
| 31 | PRINT("---=== :join test ===---", "\n\n") | 31 | PRINT("---=== :join test ===---", "\n\n") |
| 32 | 32 | ||
| 33 | -- a lane body that returns nothing is successfully joined with true, nil | ||
| 34 | local r, ret = lanes_gen(function() end)():join() | ||
| 35 | assert(r == true and ret == nil) | ||
| 36 | |||
| 33 | -- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil | 37 | -- NOTE: 'unpack()' cannot be used on the lane handle; it will always return nil |
| 34 | -- (unless [1..n] has been read earlier, in which case it would seemingly | 38 | -- (unless [1..n] has been read earlier, in which case it would seemingly |
| 35 | -- work). | 39 | -- work). |
| 36 | 40 | ||
| 37 | local S= lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, | 41 | local S = lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, |
| 38 | function(arg) | 42 | function(arg) |
| 39 | lane_threadname "join test lane" | 43 | lane_threadname "join test lane" |
| 40 | set_finalizer(function() end) | 44 | set_finalizer(function() end) |
| 45 | -- take arg table, reverse its contents in aux, then return the unpacked result | ||
| 41 | local aux= {} | 46 | local aux= {} |
| 42 | for i, v in ipairs(arg) do | 47 | for i, v in ipairs(arg) do |
| 43 | table.insert(aux, 1, v) | 48 | table.insert(aux, 1, v) |
| @@ -46,15 +51,16 @@ local S= lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, | |||
| 46 | return (unpack or table.unpack)(aux) | 51 | return (unpack or table.unpack)(aux) |
| 47 | end) | 52 | end) |
| 48 | 53 | ||
| 49 | h= S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values | 54 | local h = S { 12, 13, 14 } -- execution starts, h[1..3] will get the return values |
| 50 | -- wait a bit so that the lane has a chance to set its debug name | 55 | -- wait a bit so that the lane has a chance to set its debug name |
| 51 | SLEEP(0.5) | 56 | SLEEP(0.5) |
| 52 | print("joining with '" .. h:get_threadname() .. "'") | 57 | print("joining with '" .. h:get_threadname() .. "'") |
| 53 | local a,b,c,d= h:join() | 58 | local r, a, b, c, d = h:join() |
| 54 | if h.status == "error" then | 59 | if h.status == "error" then |
| 55 | print(h:get_threadname(), "error: " , a, b, c, d) | 60 | print(h:get_threadname(), "error: " , r, a, b, c, d) |
| 56 | else | 61 | else |
| 57 | print(h:get_threadname(), a,b,c,d) | 62 | print(h:get_threadname(), r, a, b, c, d) |
| 63 | assert(r==true, "r == " .. tostring(r)) | ||
| 58 | assert(a==14, "a == " .. tostring(a)) | 64 | assert(a==14, "a == " .. tostring(a)) |
| 59 | assert(b==13, "b == " .. tostring(b)) | 65 | assert(b==13, "b == " .. tostring(b)) |
| 60 | assert(c==12, "c == " .. tostring(c)) | 66 | assert(c==12, "c == " .. tostring(c)) |
