diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-10-09 14:57:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-10-09 14:57:16 +0800 |
commit | 2724d8838b422e3712f96f9a21243f3b9235f3f8 (patch) | |
tree | 08529330f8cbc58a30f6dcac17589537eba459d1 /server-beta | |
parent | 04285c922f096a8d928ebe6a678083b62decdb36 (diff) | |
download | lua-language-server-2724d8838b422e3712f96f9a21243f3b9235f3f8.zip |
处理一下task的参数传递
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/task.lua | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/server-beta/src/task.lua b/server-beta/src/task.lua index c7950e44..edb05fe6 100644 --- a/server-beta/src/task.lua +++ b/server-beta/src/task.lua @@ -12,19 +12,24 @@ function m.setErrorHandle(errHandle) m.errorHandle = errHandle end ---- 创建一个任务 -function m.create(callback) - local co = coroutine.create(callback) - m.coTracker[co] = true - local suc, err = coroutine.resume(co) +function m.checkResult(co, ...) + local suc, err = ... if not suc and m.errorHandle then m.errorHandle(debug.traceback(co, err)) end + return ... +end + +--- 创建一个任务 +function m.create(callback, ...) + local co = coroutine.create(callback) + m.coTracker[co] = true + return m.checkResult(co, coroutine.resume(co, ...)) end --- 休眠一段时间 ---@param time number -function m.sleep(time) +function m.sleep(time, ...) local co, main = coroutine.running() if main then if m.errorHandle then @@ -33,17 +38,14 @@ function m.sleep(time) return end timer.wait(time, function () - local suc, err = coroutine.resume(co) - if not suc and m.errorHandle then - m.errorHandle(debug.traceback(co, err)) - end + return m.checkResult(co, coroutine.resume(co)) end) - return coroutine.yield() + return coroutine.yield(...) end --- 等待直到唤醒 ---@param waker function -function m.wait(waker) +function m.wait(waker, ...) local co, main = coroutine.running() if main then if m.errorHandle then @@ -52,12 +54,9 @@ function m.wait(waker) return end waker(function (...) - local suc, err = coroutine.resume(co, ...) - if not suc and m.errorHandle then - m.errorHandle(debug.traceback(co, err)) - end + return m.checkResult(co, coroutine.resume(co, ...)) end) - return coroutine.yield() + return coroutine.yield(...) end return m |