summaryrefslogtreecommitdiff
path: root/server-beta/src/brave/brave.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-22 23:26:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-22 23:26:32 +0800
commitd0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (patch)
treebb34518d70b85de7656dbdbe958dfa221a3ff3b3 /server-beta/src/brave/brave.lua
parent0a2c2ad15e1ec359171fb0dd4c72e57c5b66e9ba (diff)
downloadlua-language-server-d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a.zip
整理一下目录结构
Diffstat (limited to 'server-beta/src/brave/brave.lua')
-rw-r--r--server-beta/src/brave/brave.lua70
1 files changed, 0 insertions, 70 deletions
diff --git a/server-beta/src/brave/brave.lua b/server-beta/src/brave/brave.lua
deleted file mode 100644
index 08909074..00000000
--- a/server-beta/src/brave/brave.lua
+++ /dev/null
@@ -1,70 +0,0 @@
-local thread = require 'bee.thread'
-
----@class pub_brave
-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
-
---- 注册能力
-function m.on(name, callback)
- m.ability[name] = callback
-end
-
---- 报告
-function m.push(name, params)
- if m.waiter then
- m.waiter:push(name, params)
- else
- m.queue[#m.queue+1] = {
- name = name,
- params = params,
- }
- end
-end
-
---- 开始找工作
-function m.start()
- m.push('mem', collectgarbage 'count')
- while true do
- local suc, name, id, params = m.taskpad:pop()
- if not suc then
- -- 找不到工作的勇者,只好睡觉
- thread.sleep(0.001)
- goto CONTINUE
- end
- local ability = m.ability[name]
- -- TODO
- if not ability then
- m.waiter:push(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(id, res)
- else
- m.waiter:push(id)
- end
- m.push('mem', collectgarbage 'count')
- ::CONTINUE::
- end
-end
-
-return m