diff options
| author | ruki <[email protected]> | 2020-02-02 23:38:43 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-07 22:45:56 +0800 |
| commit | ccfe7ed01bd603f4435ce6463ecf267f49ddd6fe (patch) | |
| tree | c483cba8234791ddc6cae960e8cdd08241525639 /xmake/core/base/process.lua | |
| parent | 81bd3dc5bfa0965ea01e1ce51a8f09fac3d9a7d0 (diff) | |
support process for scheduler
Diffstat (limited to 'xmake/core/base/process.lua')
| -rw-r--r-- | xmake/core/base/process.lua | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua index 0d4cdbf26..99f756fdc 100644 --- a/xmake/core/base/process.lua +++ b/xmake/core/base/process.lua @@ -28,6 +28,7 @@ local path = require("base/path") local utils = require("base/utils") local string = require("base/string") local coroutine = require("base/coroutine") +local scheduler = require("base/scheduler") -- save original interfaces process._open = process._open or process.open @@ -70,24 +71,60 @@ end -- @return ok, status -- function _subprocess:wait(timeout) - if not self._PROC then - return -1, 0, string.format("subprocess(%s) has been closed!", self:name()) + + -- ensure opened + local ok, errors = self:_ensure_opened() + if not ok then + return -1, errors + end + + -- wait events + local result = -1 + local status_or_errors = nil + if scheduler:co_running() then + result, status_or_errors = scheduler:poller_waitproc(self, timeout or -1) + else + result, status_or_errors = process._wait(self:cdata(), timeout or -1) end - return process._wait(self._PROC, timeout or -1) + if result < 0 and status_or_errors then + status_or_errors = string.format("%s: %s", self, status_or_errors) + end + return result, status_or_errors end -- close subprocess function _subprocess:close(timeout) - if not self._PROC then - return false, string.format("subprocess(%s) has been closed!", self:name()) + + -- ensure opened + local ok, errors = self:_ensure_opened() + if not ok then + return false, errors end - local ok = process._close(self._PROC) + + -- cancel pipe events from the scheduler + if scheduler:co_running() then + ok, errors = scheduler:poller_cancel(self) + if not ok then + return false, errors + end + end + + -- close process + ok = process._close(self:cdata()) if ok then self._PROC = nil end return ok end +-- ensure the process is opened +function _subprocess:_ensure_opened() + if not self:cdata() then + return false, string.format("%s: has been closed!", self) + end + return true +end + -- tostring(subprocess) function _subprocess:__tostring() return "<subprocess: " .. self:name() .. ">" |
