• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lunarmodules / luacheck / 23687255263

28 Mar 2026 02:28PM UTC coverage: 97.029% (-0.01%) from 97.043%
23687255263

push

github

web-flow
Merge d1d80dc7c into eea104d82

5 of 6 new or added lines in 1 file covered. (83.33%)

5 existing lines in 3 files now uncovered.

6304 of 6497 relevant lines covered (97.03%)

19847.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.36
/src/luacheck/multithreading.lua
1
local utils = require "luacheck.utils"
512✔
2

3
local multithreading = {}
512✔
4

5
local lanes_ok, lanes = pcall(require, "lanes")
512✔
6
lanes_ok = lanes_ok and pcall(lanes.configure)
512✔
7
multithreading.has_lanes = lanes_ok
512✔
8
multithreading.lanes = lanes
512✔
9
multithreading.default_jobs = 1
512✔
10

11
if not lanes_ok then
512✔
12
   return multithreading
×
13
end
14

15
local lanes_major = tonumber(lanes.ABOUT.version:match("^(%d+)"))
512✔
16
-- Manage both new and old lane:join() API formats.
17
-- See https://github.com/LuaLanes/lanes/commit/bfdc7a92c4e3e99522abb6d90ef2cbb021f36fc8
18
local worker_join_compat
19
if  lanes_major >= 4 then
512✔
20
   -- New API: {true, _, ok, worker_results}
NEW
21
   worker_join_compat = function(worker) return worker:join() end
×
22
else
23
   -- Old API: {true, ok, worker_results}
24
   worker_join_compat = function(worker)
25
      local err, ok, worker_results = worker:join()
388✔
26
      return true, err, ok, worker_results
388✔
27
   end
28
end
29

30
local cpu_number_detection_commands = {}
512✔
31

32
if utils.is_windows then
512✔
33
   cpu_number_detection_commands[1] = "echo %NUMBER_OF_PROCESSORS%"
×
34
else
35
   cpu_number_detection_commands[1] = "getconf _NPROCESSORS_ONLN 2>&1"
512✔
36
   cpu_number_detection_commands[2] = "sysctl -n hw.ncpu 2>&1"
512✔
37
   cpu_number_detection_commands[3] = "psrinfo -p 2>&1"
512✔
38
end
39

40
for _, command in ipairs(cpu_number_detection_commands) do
512✔
41
   local handler = io.popen(command)
512✔
42

43
   if handler then
512✔
44
      local output = handler:read("*a")
512✔
45
      handler:close()
512✔
46

47
      if output then
512✔
48
         local cpu_number = tonumber(utils.strip(output))
512✔
49

50
         if cpu_number then
512✔
51
            multithreading.default_jobs = math.floor(math.max(cpu_number, 1))
512✔
52
            break
256✔
53
         end
54
      end
55
   end
56
end
57

58
-- Reads pairs {key, arg} from given linda slot until it gets nil as arg.
59
-- Returns table with pairs [key] = func(arg).
60
local function worker_task(linda, input_slot, func)
61
   local results = {}
×
62

63
   while true do
64
      local _, pair = linda:receive(nil, input_slot)
×
65
      local key, arg = pair[1], pair[2]
×
66

67
      if arg == nil then
×
68
         return results
×
69
      end
70

71
      results[key] = func(arg)
×
72
   end
73
end
74

75
local function protected_worker_task(...)
76
   return true, utils.try(worker_task, ...)
×
77
end
78

79
local worker_gen = lanes.gen("*", protected_worker_task)
512✔
80

81
-- Maps func over array, performing at most jobs calls in parallel.
82
function multithreading.pmap(func, array, jobs)
512✔
83
   jobs = jobs or multithreading.default_jobs
468✔
84
   jobs = math.min(jobs, #array)
468✔
85

86
   if jobs < 2 then
468✔
87
      return utils.map(func, array)
312✔
88
   end
89

90
   local workers = {}
156✔
91
   local linda = lanes.linda()
156✔
92

93
   for i = 1, jobs do
544✔
94
      workers[i] = worker_gen(linda, 0, func)
388✔
95
   end
96

97
   for i, item in ipairs(array) do
860✔
98
      linda:send(nil, 0, {i, item})
704✔
99
   end
100

101
   for _ = 1, jobs do
544✔
102
      linda:send(nil, 0, {})
388✔
103
   end
104

105
   local results = {}
156✔
106

107
   for _, worker in ipairs(workers) do
544✔
108
      local _, __, ok, worker_results = worker_join_compat(worker)
388✔
109

110
      if ok then
388✔
111
         utils.update(results, worker_results)
388✔
112
      else
113
         error(worker_results, 0)
×
114
      end
115
   end
116

117
   return results
156✔
118
end
119

120
return multithreading
512✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc