summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/base/fwatcher.lua2
-rw-r--r--xmake/core/base/pipe.lua2
-rw-r--r--xmake/core/base/process.lua4
-rw-r--r--xmake/core/base/scheduler.lua25
-rw-r--r--xmake/core/base/socket.lua2
5 files changed, 30 insertions, 5 deletions
diff --git a/xmake/core/base/fwatcher.lua b/xmake/core/base/fwatcher.lua
index 9fc04722e..e05baa584 100644
--- a/xmake/core/base/fwatcher.lua
+++ b/xmake/core/base/fwatcher.lua
@@ -93,7 +93,7 @@ end
-- wait event
--
--- @param timeout the timeout
+-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting
--
-- @return ok, event, e.g {type = fwatcher.ET_MODIFY, path = "/tmp"}
--
diff --git a/xmake/core/base/pipe.lua b/xmake/core/base/pipe.lua
index 137f9c779..9a896afba 100644
--- a/xmake/core/base/pipe.lua
+++ b/xmake/core/base/pipe.lua
@@ -235,7 +235,7 @@ end
-- wait pipe events
--
-- @param events the events to wait, e.g. pipe.EV_READ, pipe.EV_WRITE
--- @param timeout the timeout in milliseconds, -1 for infinite
+-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting
-- @return the received events, or 0 on timeout
--
function _instance:wait(events, timeout)
diff --git a/xmake/core/base/process.lua b/xmake/core/base/process.lua
index 35b0b15b7..0c4c509b0 100644
--- a/xmake/core/base/process.lua
+++ b/xmake/core/base/process.lua
@@ -81,9 +81,9 @@ end
-- wait subprocess
--
--- @param timeout the timeout
+-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting
--
--- @return ok, status
+-- @return ok, status, e.g. -1 on error, 0 on timeout, 1 on exited
--
function _subprocess:wait(timeout)
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index 4ae8d74e0..f936f1d8f 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -982,6 +982,15 @@ function scheduler:poller_wait(obj, events, timeout)
end
end
+ -- no events yet? return immediately if timeout is zero
+ --
+ -- @note we save the waiting events, so the poller caches the events when they
+ -- arrive and the next wait returns them immediately
+ if timeout == 0 then
+ pollerdata.poller_events_wait = events_wait
+ return 0
+ end
+
-- register timeout task to timer
local timer_task = nil
if timeout > 0 then
@@ -1053,6 +1062,14 @@ function scheduler:poller_waitproc(obj, timeout)
return -1, errors
end
+ -- has not exited yet? return immediately if timeout is zero
+ --
+ -- @note we have inserted it into the poller, so its exit status is still saved
+ -- as a pending status when it exits later, and the next wait returns it immediately
+ if timeout == 0 then
+ return 0
+ end
+
-- register timeout task to timer
local timer_task = nil
if timeout > 0 then
@@ -1123,6 +1140,14 @@ function scheduler:poller_waitfs(obj, timeout)
return -1, errors
end
+ -- no event yet? return immediately if timeout is zero
+ --
+ -- @note we have inserted it into the poller, so the next event is still saved
+ -- as a pending status when it arrives, and the next wait returns it immediately
+ if timeout == 0 then
+ return 0
+ end
+
-- register timeout task to timer
local timer_task = nil
if timeout > 0 then
diff --git a/xmake/core/base/socket.lua b/xmake/core/base/socket.lua
index 393edd199..fbe1fea10 100644
--- a/xmake/core/base/socket.lua
+++ b/xmake/core/base/socket.lua
@@ -675,7 +675,7 @@ end
-- wait for socket events
--
-- @param events the events to wait, e.g. socket.EV_RECV, socket.EV_SEND
--- @param timeout the timeout in milliseconds, -1 for infinite
+-- @param timeout the timeout in milliseconds, -1 for infinite, 0 to check without waiting
-- @return the received events, or 0 on timeout
--
function _instance:wait(events, timeout)