diff options
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/base/scheduler.lua | 32 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/scheduler.lua | 30 |
2 files changed, 43 insertions, 19 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 1c6db570d..14dffce4a 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -355,6 +355,38 @@ function scheduler:co_sleep(ms) return true end +-- wait for exiting the given coroutine tasks +function scheduler:co_waitexit(cotasks) + + -- get the running coroutine + local running = self:co_running() + if not running then + return false, "we must call waitexit() in coroutine with scheduler!" + end + + -- is stopped? + if not self._STARTED then + return false, "the scheduler is stopped!" + end + + -- wait it + cotasks = table.copy(table.wrap(cotasks)) + while #cotasks > 0 do + for i = #cotasks, 1, -1 do + local co = cotasks[i] + if co:is_dead() then + table.remove(cotasks, i) + else + local ok, errors = self:co_yield() + if not ok then + return false, errors + end + end + end + end + return true +end + -- get the current running coroutine function scheduler:co_running() local running = coroutine.running() diff --git a/xmake/core/sandbox/modules/import/core/base/scheduler.lua b/xmake/core/sandbox/modules/import/core/base/scheduler.lua index 3476c9333..62bfcbb5c 100644 --- a/xmake/core/sandbox/modules/import/core/base/scheduler.lua +++ b/xmake/core/sandbox/modules/import/core/base/scheduler.lua @@ -61,16 +61,6 @@ function sandbox_core_base_scheduler.co_yield() end end --- get the current running coroutine -function sandbox_core_base_scheduler.co_running() - return scheduler:co_running() -end - --- get the all coroutine task count -function sandbox_core_base_scheduler.co_count() - return scheduler:co_count() -end - -- sleep some times (ms) function sandbox_core_base_scheduler.co_sleep(ms) local ok, errors = scheduler:co_sleep(ms) @@ -79,20 +69,22 @@ function sandbox_core_base_scheduler.co_sleep(ms) end end --- stop loop -function sandbox_core_base_scheduler.stop() - local ok, errors = scheduler:stop() +-- wait for exiting the given coroutine tasks +function sandbox_core_base_scheduler.co_waitexit(cotasks) + local ok, errors = scheduler:co_waitexit(cotasks) if not ok then raise(errors) end end --- run loop -function sandbox_core_base_scheduler.runloop() - local ok, errors = scheduler:runloop() - if not ok then - raise(errors) - end +-- get the current running coroutine +function sandbox_core_base_scheduler.co_running() + return scheduler:co_running() +end + +-- get the all coroutine task count +function sandbox_core_base_scheduler.co_count() + return scheduler:co_count() end -- return module |
