summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-24 15:23:16 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-24 15:23:16 +0800
commit4b302ec2e5aeb7a1a878989bd99c53f7f8eb84dd (patch)
tree0711364269fdacbd31ccd5536a3fb13edced38cd /server-beta
parent80b0ccb95c65a7c50f1dff91e377740b9dcdc8b0 (diff)
downloadlua-language-server-4b302ec2e5aeb7a1a878989bd99c53f7f8eb84dd.zip
修正任务队列的bug
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/main.lua4
-rw-r--r--server-beta/src/pub/pub.lua45
2 files changed, 24 insertions, 25 deletions
diff --git a/server-beta/main.lua b/server-beta/main.lua
index f9be9e53..748227ac 100644
--- a/server-beta/main.lua
+++ b/server-beta/main.lua
@@ -12,8 +12,8 @@ log.init(ROOT, ROOT / 'log' / 'service.log')
log.info('Lua Lsp startup, root: ', ROOT)
log.debug('ROOT:', ROOT:string())
-loadfile(rootPath .. '/debugger.lua')
--- 'wait'
+--loadfile(rootPath .. '/debugger.lua')'wait'
+dofile(rootPath .. '/debugger.lua')
local service = require 'service'
service.start()
diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua
index bbd2ed89..df594707 100644
--- a/server-beta/src/pub/pub.lua
+++ b/server-beta/src/pub/pub.lua
@@ -64,24 +64,12 @@ end
--- 给勇者推送任务
function m.pushTask(brave, info)
if info.removed then
- return
- end
- brave.taskpad:push(info.name, info.id, info.params)
- log.info(('Push task %q to # %d, queue length %d'):format(info.name, brave.id, #m.taskQueue))
- return task.wait(function (waker)
- info.callback = waker
- brave.taskMap[info.id] = info
- end)
-end
-
---- 给勇者推送任务(同步)
-function m.pushSyncTask(brave, info)
- if info.removed then
- return
+ return false
end
brave.taskpad:push(info.name, info.id, info.params)
brave.taskMap[info.id] = info
log.info(('Push task %q to # %d, queue length %d'):format(info.name, brave.id, #m.taskQueue))
+ return true
end
--- 从勇者处接收任务反馈
@@ -95,7 +83,9 @@ function m.popTask(brave, id, result)
m.checkWaitingTask(brave)
if not info.removed then
info.removed = true
- xpcall(info.callback, log.error, result)
+ if info.callback then
+ xpcall(info.callback, log.error, result)
+ end
end
end
@@ -120,7 +110,13 @@ function m.task(name, params)
}
for _, brave in ipairs(m.braves) do
if m.isIdle(brave) then
- return m.pushTask(brave, info)
+ if m.pushTask(brave, info) then
+ return task.wait(function (waker)
+ info.callback = waker
+ end)
+ else
+ return nil
+ end
end
end
-- 如果所有勇者都在战斗,那么把任务缓存到队列里
@@ -128,6 +124,9 @@ function m.task(name, params)
-- 交给该勇者
m.taskQueue[#m.taskQueue+1] = info
log.info(('Add task %q in queue, length %d.'):format(name, #m.taskQueue))
+ return task.wait(function (waker)
+ info.callback = waker
+ end)
end
--- 发布同步任务,如果任务进入了队列,会返回执行器
@@ -140,11 +139,11 @@ function m.syncTask(name, params, callback)
id = counter(),
name = name,
params = params,
- callback = callback or function () end,
+ callback = callback,
}
for _, brave in ipairs(m.braves) do
if m.isIdle(brave) then
- m.pushSyncTask(brave, info)
+ m.pushTask(brave, info)
return nil
end
end
@@ -188,11 +187,11 @@ function m.checkWaitingTask(brave)
if next(brave.taskMap) then
return
end
- local info = table.remove(m.taskQueue, 1)
- if info.callback then
- m.pushSyncTask(brave, info)
- else
- m.pushTask(brave, info)
+ while #m.taskQueue > 0 do
+ local info = table.remove(m.taskQueue, 1)
+ if m.pushTask(brave, info) then
+ break
+ end
end
end