summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-24 10:06:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-24 10:06:09 +0800
commit6cf50a3fdfe50baebdd2888b549c2238f35f0051 (patch)
treeb8b5459802fce548d51eaf398d2c300f8af73a00
parente3c493e3cd4954ac3f47e455025cc2922ab10099 (diff)
downloadlua-language-server-6cf50a3fdfe50baebdd2888b549c2238f35f0051.zip
附加子线程
-rw-r--r--server-beta/src/brave/brave.lua18
-rw-r--r--server-beta/src/pub/pub.lua3
2 files changed, 20 insertions, 1 deletions
diff --git a/server-beta/src/brave/brave.lua b/server-beta/src/brave/brave.lua
index 93a93142..08909074 100644
--- a/server-beta/src/brave/brave.lua
+++ b/server-beta/src/brave/brave.lua
@@ -4,12 +4,21 @@ local thread = require 'bee.thread'
local m = {}
m.type = 'brave'
m.ability = {}
+m.queue = {}
--- 注册成为勇者
function m.register(id)
m.taskpad = thread.channel('taskpad' .. id)
m.waiter = thread.channel('waiter' .. id)
m.id = id
+
+ if #m.queue > 0 then
+ for _, info in ipairs(m.queue) do
+ m.waiter:push(info.name, info.params)
+ end
+ end
+ m.queue = nil
+
m.start()
end
@@ -20,7 +29,14 @@ end
--- 报告
function m.push(name, params)
- m.waiter:push(name, params)
+ if m.waiter then
+ m.waiter:push(name, params)
+ else
+ m.queue[#m.queue+1] = {
+ name = name,
+ params = params,
+ }
+ end
end
--- 开始找工作
diff --git a/server-beta/src/pub/pub.lua b/server-beta/src/pub/pub.lua
index ca9d7382..bbd2ed89 100644
--- a/server-beta/src/pub/pub.lua
+++ b/server-beta/src/pub/pub.lua
@@ -13,6 +13,8 @@ package.cpath = %q
collectgarbage 'generational'
log = require 'brave.log'
+
+dofile(%q)
local brave = require 'brave'
brave.register(%d)
]]
@@ -44,6 +46,7 @@ function m.recruitBraves(num)
thread = thread.thread(braveTemplate:format(
package.path,
package.cpath,
+ (ROOT / 'debugger.lua'):string(),
id
)),
taskMap = {},