Skip to content

Support new lane:join() API#137

Open
Aire-One wants to merge 1 commit into
lunarmodules:masterfrom
Aire-One:fix/#135
Open

Support new lane:join() API#137
Aire-One wants to merge 1 commit into
lunarmodules:masterfrom
Aire-One:fix/#135

Conversation

@Aire-One

Copy link
Copy Markdown

Fix: #135

@alerque I went with a check on the number of retuned values to differentiate the old and new APIs. Does it work for you? Also, do you think we need some kind of tests (by mock or installing both versions in the CI) to ensure the code works with different versions of lualanes?

@alerque

alerque commented Jan 15, 2026

Copy link
Copy Markdown
Member

It sounds like testing this in CI might prove to be more brittle than just doing it. I'm inclined not to.

@daurnimator

Copy link
Copy Markdown

Is this a place where checking the version string might be better?
https://github.com/LuaLanes/lanes/blob/4aa54c9a6876c4af175b306fffe8dbc010e72c5b/src/lanes.cpp#L810-L817

@Aire-One Aire-One force-pushed the fix/#135 branch 3 times, most recently from 0c417df to aeb0e89 Compare March 18, 2026 23:38
@Aire-One

Copy link
Copy Markdown
Author

@daurnimator thank you for the suggestion.

Rebased to use the version string exposed by lanes instead of the number of parameters.

end

local lanes_major = tonumber(lanes.ABOUT.version:match("^(%d+)"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having the if in the loop below, have a function that adds backwards compat up here.

Suggested change
-- Manage both new and old lane:join() API formats.
-- See https://github.com/LuaLanes/lanes/commit/bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8
local worker_join_compat
if lanes_major >= 4 then
-- New API: {true, _, ok, worker_results}
worker_join_compat = function(worker) return worker:join() end
else
-- Old API: {true, ok, worker_results}
worker_join_compat = function(worker)
local err, ok, worker_results = worker:join()
return true, err, ok, worker_results
end
end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization, thank you!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I'm not sure if my implementation of the old API is actually correct. I didn't look very hard at what the new return values mean

@Aire-One Aire-One force-pushed the fix/#135 branch 2 times, most recently from bd38da0 to d1d80dc Compare March 28, 2026 14:28

for _, worker in ipairs(workers) do
local _, ok, worker_results = assert(worker:join())
local _, _, ok, worker_results = worker_join_compat(worker)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need the assert.

end

local lanes_major = tonumber(lanes.ABOUT.version:match("^(%d+)"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I'm not sure if my implementation of the old API is actually correct. I didn't look very hard at what the new return values mean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

INFO: API change in lane's :join() method for lanes v4.0.0 will break task handling in multithreading.lua

3 participants