diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-08-15 19:17:46 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-08-15 19:17:46 +0800 |
commit | 910fc1dae705ce2475c165ec28e20edd9cb89d61 (patch) | |
tree | bc02339f4e5a73a8a393a941058812bd53d510b0 /script-beta/await.lua | |
parent | a87e0c7cbd8ff44deb009b12efa8c28473db0470 (diff) | |
download | lua-language-server-910fc1dae705ce2475c165ec28e20edd9cb89d61.zip |
允许给 await 设置一个全局的延迟检查器
Diffstat (limited to 'script-beta/await.lua')
-rw-r--r-- | script-beta/await.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/script-beta/await.lua b/script-beta/await.lua index 5ee9e20b..78f40e66 100644 --- a/script-beta/await.lua +++ b/script-beta/await.lua @@ -4,8 +4,9 @@ local timer = require 'timer' local m = {} m.type = 'await' -m.coTracker = setmetatable({}, { __mode = 'k' }) +m.coTracker = setmetatable({}, { __mode = 'k' }) m.coPriority = setmetatable({}, { __mode = 'k' }) +m.coDelayer = setmetatable({}, { __mode = 'k' }) m.delayQueue = {} m.delayQueueIndex = 1 @@ -30,6 +31,11 @@ function m.create(callback, ...) return m.checkResult(co, coroutine.resume(co, ...)) end +function m.setDelayer(callback) + local co = coroutine.running() + m.coDelayer[co] = callback +end + --- 休眠一段时间 ---@param time number function m.sleep(time, getVersion) @@ -75,8 +81,11 @@ function m.delay(getVersion) return end local version = getVersion and getVersion() + local delayer = m.coDelayer[co] + local dVersion = delayer and delayer() m.delayQueue[#m.delayQueue+1] = function () - if version == (getVersion and getVersion()) then + if version == (getVersion and getVersion()) + and dVersion == (delayer and delayer()) then return m.checkResult(co, coroutine.resume(co)) else coroutine.close(co) |