summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-06-05 17:21:19 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-06-05 17:21:19 +0800
commit086b7a1431ee0cfb2fd24ec2bf1e1599e0f21bc8 (patch)
treea38e6c67ee22ba48f6dca22cf5ebb4ed3e5f219b
parentbf56967a8c42aedf28d4512a054730e68eb377da (diff)
downloadlua-language-server-086b7a1431ee0cfb2fd24ec2bf1e1599e0f21bc8.zip
Revert "update bee"
This reverts commit 719d7c2ba63c5a0207604a40cdf0b78a02b0eb78.
-rw-r--r--.gitignore3
-rw-r--r--.vs/launch.vs.json16
-rw-r--r--script/brave/brave.lua30
-rw-r--r--script/pub/pub.lua38
4 files changed, 17 insertions, 70 deletions
diff --git a/.gitignore b/.gitignore
index 55b95593..4d868571 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,3 @@
!/meta/3rd
!/meta/whimsical
/bin*
-/.vs/*
-!/.vs/launch.vs.json
-!/.vs/tasks.vs.json
diff --git a/.vs/launch.vs.json b/.vs/launch.vs.json
deleted file mode 100644
index 6a6569d5..00000000
--- a/.vs/launch.vs.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "version": "0.2.1",
- "defaults": {},
- "configurations": [
- {
- "type": "native",
- "name": "debug",
- "project": "bin\\lua-language-server.exe",
- "args": [
- "test.lua"
- ],
- "currentDir": ".",
- "projectTarget": ""
- }
- ]
-} \ No newline at end of file
diff --git a/script/brave/brave.lua b/script/brave/brave.lua
index 9606c6d8..9ad7ebd1 100644
--- a/script/brave/brave.lua
+++ b/script/brave/brave.lua
@@ -1,27 +1,7 @@
-local channel = require 'bee.channel'
-local select = require 'bee.select'
local thread = require 'bee.thread'
-local function channel_init(chan)
- local selector = select.create()
- selector:event_add(chan:fd(), select.SELECT_READ)
- return { selector, chan }
-end
-
-local function channel_bpop(ctx)
- local selector, chan = ctx[1], ctx[2]
- while true do
- for _ in selector:wait() do
- local r = table.pack(chan:pop())
- if r[1] == true then
- return table.unpack(r, 2)
- end
- end
- end
-end
-
-local taskPad = channel_init(channel.query('taskpad'))
-local waiter = channel.query('waiter')
+local taskPad = thread.channel('taskpad')
+local waiter = thread.channel('waiter')
---@class pub_brave
local m = {}
@@ -62,11 +42,11 @@ end
--- 开始找工作
function m.start(privatePad)
- local reqPad = privatePad and channel_init(channel.query('req:' .. privatePad)) or taskPad
- local resPad = privatePad and channel.query('res:' .. privatePad) or waiter
+ local reqPad = privatePad and thread.channel('req:' .. privatePad) or taskPad
+ local resPad = privatePad and thread.channel('res:' .. privatePad) or waiter
m.push('mem', collectgarbage 'count')
while true do
- local name, id, params = channel_bpop(reqPad)
+ local name, id, params = reqPad:bpop()
local ability = m.ability[name]
-- TODO
if not ability then
diff --git a/script/pub/pub.lua b/script/pub/pub.lua
index ef9e4b41..5bbb381c 100644
--- a/script/pub/pub.lua
+++ b/script/pub/pub.lua
@@ -1,29 +1,13 @@
local thread = require 'bee.thread'
-local channel = require 'bee.channel'
-local select = require 'bee.select'
local utility = require 'utility'
local await = require 'await'
-local function channel_init(chan)
- local selector = select.create()
- selector:event_add(chan:fd(), select.SELECT_READ)
- return { selector, chan }
-end
-
-local function channel_bpop(ctx)
- local selector, chan = ctx[1], ctx[2]
- while true do
- for _ in selector:wait() do
- local r = table.pack(chan:pop())
- if r[1] == true then
- return table.unpack(r, 2)
- end
- end
- end
-end
+thread.newchannel 'taskpad'
+thread.newchannel 'waiter'
-local taskPad = channel.create 'taskpad'
-local waiter = channel_init(channel.create 'waiter')
+local errLog = thread.channel 'errlog'
+local taskPad = thread.channel 'taskpad'
+local waiter = thread.channel 'waiter'
local type = type
local counter = utility.counter()
@@ -82,9 +66,11 @@ function m.recruitBraves(num, privatePad)
}
end
if privatePad and not m.prvtPad[privatePad] then
+ thread.newchannel('req:' .. privatePad)
+ thread.newchannel('res:' .. privatePad)
m.prvtPad[privatePad] = {
- req = channel.create('req:' .. privatePad),
- res = channel.create('res:' .. privatePad),
+ req = thread.channel('req:' .. privatePad),
+ res = thread.channel('res:' .. privatePad),
}
end
end
@@ -180,7 +166,7 @@ end
--- 接收反馈
function m.recieve(block)
if block then
- local id, name, result = channel_bpop(waiter)
+ local id, name, result = waiter:bpop()
if type(name) == 'string' then
m.popReport(m.braves[id], name, result)
else
@@ -189,7 +175,7 @@ function m.recieve(block)
else
while true do
local ok
- if m.reciveFromPad(waiter[2]) then
+ if m.reciveFromPad(waiter) then
ok = true
end
for _, pad in pairs(m.prvtPad) do
@@ -208,7 +194,7 @@ end
--- 检查伤亡情况
function m.checkDead()
while true do
- local suc, err = thread.errlog()
+ local suc, err = errLog:pop()
if not suc then
break
end