Skip to content

Commit aeb0e89

Browse files
committed
fix(multithreading): support new lane:join() API
1 parent eea104d commit aeb0e89

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/luacheck/multithreading.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
-- luacheck: push compat
2+
local unpack = table.unpack or unpack
3+
-- luacheck: pop
4+
15
local utils = require "luacheck.utils"
26

37
local multithreading = {}
@@ -12,6 +16,8 @@ if not lanes_ok then
1216
return multithreading
1317
end
1418

19+
local lanes_major = tonumber(lanes.ABOUT.version:match("^(%d+)"))
20+
1521
local cpu_number_detection_commands = {}
1622

1723
if utils.is_windows then
@@ -90,7 +96,18 @@ function multithreading.pmap(func, array, jobs)
9096
local results = {}
9197

9298
for _, worker in ipairs(workers) do
93-
local _, ok, worker_results = assert(worker:join())
99+
local join_results = {worker:join()}
100+
101+
-- Manage both new and old lane:join() API formats.
102+
-- See https://github.com/LuaLanes/lanes/commit/bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8
103+
local ok, worker_results, _
104+
if lanes_major >= 4 then
105+
-- New API: {true, _, ok, worker_results}
106+
_, _, ok, worker_results = unpack(join_results)
107+
else
108+
-- Old API: {true, ok, worker_results}
109+
_, ok, worker_results = unpack(join_results)
110+
end
94111

95112
if ok then
96113
utils.update(results, worker_results)

0 commit comments

Comments
 (0)