summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-04 22:45:20 +0800
committerruki <[email protected]>2020-02-07 22:45:56 +0800
commit9d205f5db11e184073990883e1a7b94d1d4b783b (patch)
treec1bcbe63eed773600d601aaf82629cd2f8b3db57
parent0c3f6069c16dbc7b6612fb792cbe6b990a7acef2 (diff)
improve co_waitexit
-rw-r--r--xmake/core/base/scheduler.lua29
1 files changed, 2 insertions, 27 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index 14dffce4a..d53f9363a 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -292,32 +292,7 @@ end
-- yield the current coroutine
function scheduler:co_yield()
-
- -- get the running coroutine
- local running = self:co_running()
- if not running then
- return false, "we must call co_yield() in coroutine with scheduler!"
- end
-
- -- is stopped?
- if not self._STARTED then
- return false, "the scheduler is stopped!"
- end
-
- -- register timeout task to timer without 0 ms (no delay)
- self:_timer():post(function (cancel)
- if running:is_suspended() then
- self:_co_tasks_suspended():remove(running)
- self:co_resume(running)
- end
- end, 0)
-
- -- save the suspended coroutine
- self:_co_tasks_suspended():insert(running)
-
- -- wait
- self:co_suspend()
- return true
+ return scheduler.co_sleep(1)
end
-- sleep some times (ms)
@@ -377,7 +352,7 @@ function scheduler:co_waitexit(cotasks)
if co:is_dead() then
table.remove(cotasks, i)
else
- local ok, errors = self:co_yield()
+ local ok, errors = self:co_sleep(100)
if not ok then
return false, errors
end