diff options
author | actboy168 <actboy168@gmail.com> | 2024-05-07 12:30:35 +0800 |
---|---|---|
committer | actboy168 <actboy168@gmail.com> | 2024-05-07 12:30:35 +0800 |
commit | 719d7c2ba63c5a0207604a40cdf0b78a02b0eb78 (patch) | |
tree | 30821594763325865ca605b26142a2b8879abf83 /script/pub/pub.lua | |
parent | 94b06e3548424d08e93a2758135d689c0f8986d4 (diff) | |
download | lua-language-server-719d7c2ba63c5a0207604a40cdf0b78a02b0eb78.zip |
update bee
Diffstat (limited to 'script/pub/pub.lua')
-rw-r--r-- | script/pub/pub.lua | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/script/pub/pub.lua b/script/pub/pub.lua index 5bbb381c..e8be65cd 100644 --- a/script/pub/pub.lua +++ b/script/pub/pub.lua @@ -1,13 +1,27 @@ local thread = require 'bee.thread' +local channel = require 'bee.channel' +local select = require 'bee.select' local utility = require 'utility' local await = require 'await' -thread.newchannel 'taskpad' -thread.newchannel 'waiter' +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] + for _ in selector:wait() do + local r = table.pack(chan:pop()) + if r[1] == true then + return table.unpack(r, 2) + end + end +end -local errLog = thread.channel 'errlog' -local taskPad = thread.channel 'taskpad' -local waiter = thread.channel 'waiter' +local taskPad = channel.create 'taskpad' +local waiter = channel_init(channel.create 'waiter') local type = type local counter = utility.counter() @@ -66,11 +80,9 @@ 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 = thread.channel('req:' .. privatePad), - res = thread.channel('res:' .. privatePad), + req = channel.create('req:' .. privatePad), + res = channel.create('res:' .. privatePad), } end end @@ -166,7 +178,7 @@ end --- 接收反馈 function m.recieve(block) if block then - local id, name, result = waiter:bpop() + local id, name, result = channel_bpop(waiter) if type(name) == 'string' then m.popReport(m.braves[id], name, result) else @@ -175,7 +187,7 @@ function m.recieve(block) else while true do local ok - if m.reciveFromPad(waiter) then + if m.reciveFromPad(waiter[2]) then ok = true end for _, pad in pairs(m.prvtPad) do @@ -194,7 +206,7 @@ end --- 检查伤亡情况 function m.checkDead() while true do - local suc, err = errLog:pop() + local suc, err = thread.errlog() if not suc then break end |