diff options
| author | ruki <[email protected]> | 2024-03-18 23:44:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-03-18 23:44:06 +0800 |
| commit | ca16db30058d8a512d73a7bee28e57f72de4c338 (patch) | |
| tree | 37f034b25bf468297daa0ec4bc8dd5490f380c5e /xmake/modules/async/runjobs.lua | |
| parent | ef76c91d0517361173246f6ee62b3b6c3ba1e29e (diff) | |
improve progress
Diffstat (limited to 'xmake/modules/async/runjobs.lua')
| -rw-r--r-- | xmake/modules/async/runjobs.lua | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/xmake/modules/async/runjobs.lua b/xmake/modules/async/runjobs.lua index 19090da5d..476efe08f 100644 --- a/xmake/modules/async/runjobs.lua +++ b/xmake/modules/async/runjobs.lua @@ -40,12 +40,12 @@ end -- runjobs("test", function () os.sleep(10000) end, { progress = { chars = {'/','\'} } }) -- see module utils.progress -- -- local jobs = jobpool.new() --- local root = jobs:addjob("job/root", function (idx, total) --- print(idx, total) +-- local root = jobs:addjob("job/root", function (index, total) +-- print(index, total) -- end) -- for i = 1, 3 do --- local job = jobs:addjob("job/" .. i, function (idx, total) --- print(idx, total) +-- local job = jobs:addjob("job/" .. i, function (index, total) +-- print(index, total) -- end, {rootjob = root}) -- end -- runjobs("test", jobs, {comax = 6, timeout = 1000, on_timer = function (running_jobs_indices) end}) @@ -154,12 +154,30 @@ function main(name, jobs, opt) -- run jobs local index = 0 local count = 0 - local count_as_index = opt.count_as_index local priority_prev = 0 local priority_curr = 0 local job_pending = nil local abort = false local abort_errors + local progress_wrapper = {} + progress_wrapper.current = function () + return count + end + progress_wrapper.total = function () + return total + end + progress_wrapper.percent = function () + if total and total > 0 then + return math.floor((count * 100) / total) + else + return 0 + end + end + debug.setmetatable(progress_wrapper, { + __tostring = function () + return string.format("%d%%", progress_wrapper.percent()) + end + }) while index < total do scheduler.co_group_begin(group_name, function (co_group) local freemax = comax - #co_group @@ -234,7 +252,7 @@ function main(name, jobs, opt) if opt.curdir then os.cd(opt.curdir) end - jobfunc(count_as_index and count or i, total) + jobfunc(i, total, {progress = progress_wrapper}) count = count + 1 end running_jobs_indices[i] = nil |
