diff options
| author | ruki <[email protected]> | 2020-02-05 22:33:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-07 22:45:56 +0800 |
| commit | 69a092643d7725dce1f6fbf7b90ddb3e6f15370e (patch) | |
| tree | d86f3b08dddc1ec5b0b1dea0f8d035b9f1459dfb | |
| parent | 35ffc50b1dc6abc88586ac1986607db16772c686 (diff) | |
uses runjobs instead of process.asyncrun
| -rw-r--r-- | tests/modules/scheduler/runjobs.lua | 5 | ||||
| -rw-r--r-- | xmake/actions/update/main.lua | 5 | ||||
| -rw-r--r-- | xmake/core/base/process.lua | 69 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/process.lua | 26 | ||||
| -rw-r--r-- | xmake/modules/private/async/runjobs.lua | 26 | ||||
| -rw-r--r-- | xmake/plugins/repo/main.lua | 3 |
6 files changed, 36 insertions, 98 deletions
diff --git a/tests/modules/scheduler/runjobs.lua b/tests/modules/scheduler/runjobs.lua index 7fea9bf66..2686dd43f 100644 --- a/tests/modules/scheduler/runjobs.lua +++ b/tests/modules/scheduler/runjobs.lua @@ -14,5 +14,10 @@ function main() runjobs("test", _jobfunc, {total = 100, comax = 6, timeout = 1000, timer = function (running_jobs_indices) print("%s: timeout (%d ms), running: %s", scheduler.co_running(), os.mclock() - t, table.concat(running_jobs_indices, ",")) end}) + printf("testing .. ") + runjobs("test", function () + os.sleep(10000) + end, {showtips = true}) + print("ok") end diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 037ea7e5d..a0aa4bd4a 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -28,6 +28,7 @@ import("devel.git.submodule") import("net.fasturl") import("core.base.privilege") import("privilege.sudo") +import("private.async.runjobs") import("actions.require.impl.environment", {rootdir = os.programdir()}) import("private.action.update.fetch_version") @@ -194,7 +195,7 @@ function _install(sourcedir) if option.get("verbose") then install_task() else - process.asyncrun(install_task) + runjobs("update/install", install_task, {showtips = true}) end -- show version @@ -376,7 +377,7 @@ function main() if option.get("verbose") then download_task() else - process.asyncrun(download_task) + runjobs("update/download", download_task, {showtips = true}) end -- leave environment diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua index f1a263260..2abcfa00b 100644 --- a/xmake/core/base/process.lua +++ b/xmake/core/base/process.lua @@ -224,74 +224,5 @@ function process.openv(shellname, argv, opt) end end --- async run task and echo waiting info -function process.asyncrun(task, waitchars) - - -- create a coroutine task - task = coroutine.create(task) - - -- we need hide wait characters if is not a tty - local show_wait = io.isatty() - - -- trace - local waitindex = 0 - local waitchars = waitchars or {'\\', '-', '/', '|'} - if show_wait then - utils.printf(waitchars[waitindex + 1]) - end - io.flush() - - -- start and wait this task - local ok, errors = coroutine.resume(task) - if not ok then - - -- remove wait charactor - if show_wait then - utils.printf("\b") - io.flush() - end - - -- failed - return false, errors - end - - -- wait and poll task - while coroutine.status(task) ~= "dead" do - - -- trace - if show_wait then - waitindex = ((waitindex + 1) % #waitchars) - utils.printf("\b" .. waitchars[waitindex + 1]) - end - io.flush() - - -- wait some time - os.sleep(300) - - -- continue to poll this task - local ok, errors = coroutine.resume(task, 0) - if not ok then - - -- remove wait charactor - if show_wait then - utils.printf("\b") - io.flush() - end - - -- failed - return false, errors - end - end - - -- remove wait charactor - if show_wait then - utils.printf("\b") - io.flush() - end - - -- ok - return true -end - -- return module: process return process diff --git a/xmake/core/sandbox/modules/process.lua b/xmake/core/sandbox/modules/process.lua index de46625a1..6b9a16728 100644 --- a/xmake/core/sandbox/modules/process.lua +++ b/xmake/core/sandbox/modules/process.lua @@ -113,31 +113,5 @@ function sandbox_process.openv(filename, argv, opt) return proc end --- wait processes -function sandbox_process.waitlist(processes, timeout) - - -- check - assert(processes) - - -- wait them - local count, infos = process.waitlist(processes, timeout) - if count < 0 then - raise("wait processes(%d) failed(%d)", #processes, count) - end - - -- timeout or finished - return infos -end - --- async run task and echo waiting info -function sandbox_process.asyncrun(task, waitchars) - - -- async run it - local ok, errors = process.asyncrun(task, waitchars) - if not ok then - raise(errors) - end -end - -- return module return sandbox_process diff --git a/xmake/modules/private/async/runjobs.lua b/xmake/modules/private/async/runjobs.lua index bc2be74ca..b59bd3a35 100644 --- a/xmake/modules/private/async/runjobs.lua +++ b/xmake/modules/private/async/runjobs.lua @@ -29,6 +29,15 @@ function main(name, jobfunc, opt) local total = opt.total or 1 local comax = opt.comax or total + -- show waiting tips? + local waitindex = 0 + local waitchars = opt.waitchars or {'\\', '-', '/', '|'} + local showtips = io.isatty() and opt.showtips -- we need hide wait characters if is not a tty + if showtips then + printf(waitchars[waitindex + 1]) + io.flush() + end + -- run timer local stop = false local running_jobs_indices @@ -42,6 +51,17 @@ function main(name, jobfunc, opt) end end end) + elseif showtips then + scheduler.co_start_named(name .. "/tips", function () + while not stop do + os.sleep(opt.timeout or 300) + if not stop then + waitindex = ((waitindex + 1) % #waitchars) + printf("\b" .. waitchars[waitindex + 1]) + io.flush() + end + end + end) end -- run jobs @@ -62,4 +82,10 @@ function main(name, jobfunc, opt) -- stop timer stop = true + + -- remove wait charactor + if showtips then + printf("\b") + io.flush() + end end diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua index 91cd9f515..41f015451 100644 --- a/xmake/plugins/repo/main.lua +++ b/xmake/plugins/repo/main.lua @@ -25,6 +25,7 @@ import("core.project.project") import("core.platform.platform") import("core.package.repository") import("devel.git") +import("private.async.runjobs") import("actions.require.impl.environment", {rootdir = os.programdir()}) -- add repository url @@ -132,7 +133,7 @@ function _update() if option.get("verbose") then task() else - process.asyncrun(task) + runjobs("update repo", task, {showtips = true}) end -- leave environment |
