diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-24 15:57:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-24 15:57:07 +0800 |
commit | d3747e09567909eed1917c65b19eeef24315e3dd (patch) | |
tree | 9af9d4a18acae7db430fa59dd98168524439e820 | |
parent | 4b302ec2e5aeb7a1a878989bd99c53f7f8eb84dd (diff) | |
download | lua-language-server-d3747e09567909eed1917c65b19eeef24315e3dd.zip |
读取协议是常驻任务
-rw-r--r-- | server-beta/src/brave/init.lua | 2 | ||||
-rw-r--r-- | server-beta/src/proto/proto.lua | 11 | ||||
-rw-r--r-- | server-beta/src/pub/init.lua | 9 | ||||
-rw-r--r-- | server-beta/src/pub/pub.lua | 7 | ||||
-rw-r--r-- | server-beta/src/task.lua | 1 |
5 files changed, 15 insertions, 15 deletions
diff --git a/server-beta/src/brave/init.lua b/server-beta/src/brave/init.lua index 4616110f..0a2d2d25 100644 --- a/server-beta/src/brave/init.lua +++ b/server-beta/src/brave/init.lua @@ -9,7 +9,7 @@ brave.on('loadProto', function () while true do local proto = jsonrpc.decode(io.read, log.error) if proto then - return proto + brave.push('proto', proto) end end end) diff --git a/server-beta/src/proto/proto.lua b/server-beta/src/proto/proto.lua index cc9988a8..27ba68b8 100644 --- a/server-beta/src/proto/proto.lua +++ b/server-beta/src/proto/proto.lua @@ -112,16 +112,7 @@ function m.listen() subprocess.filemode(io.stdout, 'b') io.stdin:setvbuf 'no' io.stdout:setvbuf 'no' - task.create(function () - while true do - local proto = pub.task('loadProto') - if proto.method then - m.doMethod(proto) - else - m.doResponse(proto) - end - end - end) + pub.syncTask('loadProto') end return m diff --git a/server-beta/src/pub/init.lua b/server-beta/src/pub/init.lua index bf188e8d..65343d64 100644 --- a/server-beta/src/pub/init.lua +++ b/server-beta/src/pub/init.lua @@ -8,4 +8,13 @@ pub.on('mem', function (count, brave) brave.memory = count end) +pub.on('proto', function (params) + local proto = require 'proto' + if params.method then + proto.doMethod(params) + else + proto.doResponse(params) + end +end) + return pub diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua index df594707..4f245517 100644 --- a/server-beta/src/pub/pub.lua +++ b/server-beta/src/pub/pub.lua @@ -68,7 +68,7 @@ function m.pushTask(brave, info) 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)) + log.info(('Push task %q(%d) to # %d, queue length %d'):format(info.name, info.id, brave.id, #m.taskQueue)) return true end @@ -80,6 +80,7 @@ function m.popTask(brave, id, result) return end brave.taskMap[id] = nil + log.info(('Pop task %q(%d) from # %d'):format(info.name, info.id, brave.id)) m.checkWaitingTask(brave) if not info.removed then info.removed = true @@ -123,7 +124,7 @@ function m.task(name, params) -- 当有勇者提交任务反馈后,尝试把按顺序将堆积任务 -- 交给该勇者 m.taskQueue[#m.taskQueue+1] = info - log.info(('Add task %q in queue, length %d.'):format(name, #m.taskQueue)) + log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) return task.wait(function (waker) info.callback = waker end) @@ -151,7 +152,7 @@ function m.syncTask(name, params, callback) -- 当有勇者提交任务反馈后,尝试把按顺序将堆积任务 -- 交给该勇者 m.taskQueue[#m.taskQueue+1] = info - log.info(('Add task %q in queue, length %d.'):format(name, #m.taskQueue)) + log.info(('Add task %q(%d) in queue, length %d.'):format(name, info.id, #m.taskQueue)) return info end diff --git a/server-beta/src/task.lua b/server-beta/src/task.lua index ba7bec94..b4cf46d0 100644 --- a/server-beta/src/task.lua +++ b/server-beta/src/task.lua @@ -1,6 +1,5 @@ local timer = require 'timer' - ---@class task local m = {} m.type = 'task' |