summaryrefslogtreecommitdiff
path: root/script/brave/brave.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-02-09 16:59:21 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-02-09 16:59:21 +0800
commit8203564f88be814227d2ea88d67c0cbd97987f50 (patch)
treee7d1ec2be936f23a528624a6988f943e608a7ccc /script/brave/brave.lua
parentbad352124b71e61e74c9fd326868086798cad83a (diff)
downloadlua-language-server-8203564f88be814227d2ea88d67c0cbd97987f50.zip
some fix
Diffstat (limited to 'script/brave/brave.lua')
-rw-r--r--script/brave/brave.lua21
1 files changed, 11 insertions, 10 deletions
diff --git a/script/brave/brave.lua b/script/brave/brave.lua
index c5ad733b..36b56b54 100644
--- a/script/brave/brave.lua
+++ b/script/brave/brave.lua
@@ -1,5 +1,8 @@
local thread = require 'bee.thread'
+local taskPad = thread.channel('taskpad')
+local waiter = thread.channel('waiter')
+
---@class pub_brave
local m = {}
m.type = 'brave'
@@ -8,13 +11,11 @@ m.queue = {}
--- 注册成为勇者
function m.register(id)
- m.taskpad = thread.channel('taskpad' .. id)
- m.waiter = thread.channel('waiter' .. id)
- m.id = id
+ m.id = id
if #m.queue > 0 then
for _, info in ipairs(m.queue) do
- m.waiter:push(m.id, info.name, info.params)
+ waiter:push(m.id, info.name, info.params)
end
end
m.queue = nil
@@ -29,8 +30,8 @@ end
--- 报告
function m.push(name, params)
- if m.waiter then
- m.waiter:push(m.id, name, params)
+ if m.id then
+ waiter:push(m.id, name, params)
else
m.queue[#m.queue+1] = {
name = name,
@@ -43,19 +44,19 @@ end
function m.start()
m.push('mem', collectgarbage 'count')
while true do
- local name, id, params = m.taskpad:bpop()
+ local name, id, params = taskPad:bpop()
local ability = m.ability[name]
-- TODO
if not ability then
- m.waiter:push(m.id, id)
+ waiter:push(m.id, id)
log.error('Brave can not handle this work: ' .. name)
goto CONTINUE
end
local ok, res = xpcall(ability, log.error, params)
if ok then
- m.waiter:push(m.id, id, res)
+ waiter:push(m.id, id, res)
else
- m.waiter:push(m.id, id)
+ waiter:push(m.id, id)
end
m.push('mem', collectgarbage 'count')
::CONTINUE::