summaryrefslogtreecommitdiff
path: root/script-beta/await.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-02 15:48:00 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-02 15:48:00 +0800
commit5243d38793549354fc137831f3481137a882f77e (patch)
treeb624421f4d52ecfc0503bf88b6f1bdcb12108447 /script-beta/await.lua
parent614196b67198e3e0765a25b6b9c1b0a45624855e (diff)
downloadlua-language-server-5243d38793549354fc137831f3481137a882f77e.zip
后台诊断速率
Diffstat (limited to 'script-beta/await.lua')
-rw-r--r--script-beta/await.lua23
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