diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-11 12:39:34 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-11 12:39:34 +0800 |
commit | 57b8f00759bedec39cd22b7deeb22e59de80fabc (patch) | |
tree | a04ae25fbe60197386cb71f90166dacc34ff7f2c /server-beta/src | |
parent | 23f0c601cbc175b1acdca271423cbcb372abfc38 (diff) | |
download | lua-language-server-57b8f00759bedec39cd22b7deeb22e59de80fabc.zip |
不可yield的地方让出不报错
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/await.lua | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/server-beta/src/await.lua b/server-beta/src/await.lua index 92db7f73..c744e1be 100644 --- a/server-beta/src/await.lua +++ b/server-beta/src/await.lua @@ -32,13 +32,13 @@ end --- 休眠一段时间 ---@param time number function m.sleep(time, ...) - local co, main = coroutine.running() - if main then + if not coroutine.isyieldable() then if m.errorHandle then - m.errorHandle(debug.traceback('Cant sleep in main thread')) + m.errorHandle(debug.traceback('Cannot yield')) end return end + local co = coroutine.running() timer.wait(time, function () return m.checkResult(co, coroutine.resume(co)) end) @@ -48,13 +48,10 @@ end --- 等待直到唤醒 ---@param callback function function m.wait(callback, ...) - local co, main = coroutine.running() - if main then - if m.errorHandle then - m.errorHandle(debug.traceback('Cant wait in main thread')) - end + if not coroutine.isyieldable() then return end + local co = coroutine.running() callback(function (...) return m.checkResult(co, coroutine.resume(co, ...)) end) @@ -63,13 +60,10 @@ end --- 延迟 function m.delay(getVersion) - local co, main = coroutine.running() - if main then - if m.errorHandle then - m.errorHandle(debug.traceback('Cant wait in main thread')) - end + if not coroutine.isyieldable() then return end + local co = coroutine.running() local version = getVersion and getVersion() m.delayQueue[#m.delayQueue+1] = function () if version == (getVersion and getVersion()) then |