diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-02 15:48:00 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-02 15:48:00 +0800 |
commit | 5243d38793549354fc137831f3481137a882f77e (patch) | |
tree | b624421f4d52ecfc0503bf88b6f1bdcb12108447 /script-beta/await.lua | |
parent | 614196b67198e3e0765a25b6b9c1b0a45624855e (diff) | |
download | lua-language-server-5243d38793549354fc137831f3481137a882f77e.zip |
后台诊断速率
Diffstat (limited to 'script-beta/await.lua')
-rw-r--r-- | script-beta/await.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/script-beta/await.lua b/script-beta/await.lua index 558c273e..50406918 100644 --- a/script-beta/await.lua +++ b/script-beta/await.lua @@ -9,6 +9,7 @@ m.coMap = setmetatable({}, { __mode = 'k' }) m.idMap = {} m.delayQueue = {} m.delayQueueIndex = 1 +m.watchList = {} m._enable = true --- 设置错误处理器 @@ -89,6 +90,11 @@ function m.close(id) log.debug('Close await:', id, count) end +function m.hasID(id, co) + co = co or coroutine.running() + return m.idMap[id] and m.idMap[id][co] ~= nil +end + --- 休眠一段时间 ---@param time number function m.sleep(time) @@ -139,6 +145,9 @@ function m.delay() end local co = coroutine.running() local current = m.coMap[co] + if m.onWatch('delay', co) == false then + return + end -- TODO if current.priority then return @@ -184,4 +193,18 @@ function m.disable() m._enable = false end +--- 注册事件 +function m.watch(callback) + m.watchList[#m.watchList+1] = callback +end + +function m.onWatch(ev, ...) + for _, callback in ipairs(m.watchList) do + local res = callback(ev, ...) + if res ~= nil then + return res + end + end +end + return m |