diff options
Diffstat (limited to 'xmake/core/base/scheduler.lua')
| -rw-r--r-- | xmake/core/base/scheduler.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua index 677b50409..5c916bdce 100644 --- a/xmake/core/base/scheduler.lua +++ b/xmake/core/base/scheduler.lua @@ -121,8 +121,12 @@ function scheduler:co_start_named(coname, cotask, ...) co = _coroutine.new(coname, coroutine.create(function(...) cotask(...) self:co_tasks()[co:thread()] = nil + if self:co_count() > 0 then + self._CO_COUNT = self:co_count() - 1 + end end)) self:co_tasks()[co:thread()] = co + self._CO_COUNT = self:co_count() + 1 local ok, errors = scheduler:co_resume(co, ...) if not ok then return nil, errors @@ -156,6 +160,11 @@ function scheduler:co_tasks() return cotasks end +-- get all coroutine count +function scheduler:co_count() + return self._CO_COUNT or 0 +end + -- wait socket events function scheduler:waitsock(sock, events, timeout) |
