diff options
| author | ruki <[email protected]> | 2019-11-28 22:43:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-11-28 10:18:18 +0800 |
| commit | 6e42cbc962f56c1e841f66cfda0e4c8f8cde787a (patch) | |
| tree | aa290f75a273a0dc603ef2de35778e790bba8ca5 /xmake/core/base/scheduler.lua | |
| parent | 5419b4eb3112fbe9b43249c62f9e319518caa71e (diff) | |
switch socket/wait to scheduler/wait
Diffstat (limited to 'xmake/core/base/scheduler.lua')
| -rw-r--r-- | xmake/core/base/scheduler.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 426523a68..b0f50f963 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -58,10 +58,34 @@ function scheduler:run(func, ...) return true end +-- get the current running coroutine in scheduler +function scheduler:running() + return self._RUNNING and coroutine.running() or nil +end + +-- wait socket/pipe and process events +function scheduler:wait(object, events, timeout) + + -- ensure to run on coroutine with scheduler + if not self:running() then + return -1, "please wait events on coroutine with scheduler!" + end + + -- TODO +end + -- TODO -- run loop, schedule coroutine with socket/io and sub-processes function scheduler:runloop(opt) + -- ensure only one scheduler + if self._RUNNING then + return false, "there is already a running scheduler!" + end + + -- start scheduler + self._RUNNING = true + -- run loop local coroutines_ready = self:_coroutines_ready() while #coroutines_ready > 0 do @@ -80,6 +104,9 @@ function scheduler:runloop(opt) table.remove(coroutines_ready, 1) end end + + -- stop scheduler + self._RUNNING = false return true end |
