Skip to content

Commit 086b7a1

Browse files
committed
Revert "update bee"
This reverts commit 719d7c2.
1 parent bf56967 commit 086b7a1

File tree

4 files changed

+17
-70
lines changed

4 files changed

+17
-70
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@
66
!/meta/3rd
77
!/meta/whimsical
88
/bin*
9-
/.vs/*
10-
!/.vs/launch.vs.json
11-
!/.vs/tasks.vs.json

.vs/launch.vs.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

script/brave/brave.lua

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
1-
local channel = require 'bee.channel'
2-
local select = require 'bee.select'
31
local thread = require 'bee.thread'
42

5-
local function channel_init(chan)
6-
local selector = select.create()
7-
selector:event_add(chan:fd(), select.SELECT_READ)
8-
return { selector, chan }
9-
end
10-
11-
local function channel_bpop(ctx)
12-
local selector, chan = ctx[1], ctx[2]
13-
while true do
14-
for _ in selector:wait() do
15-
local r = table.pack(chan:pop())
16-
if r[1] == true then
17-
return table.unpack(r, 2)
18-
end
19-
end
20-
end
21-
end
22-
23-
local taskPad = channel_init(channel.query('taskpad'))
24-
local waiter = channel.query('waiter')
3+
local taskPad = thread.channel('taskpad')
4+
local waiter = thread.channel('waiter')
255

266
---@class pub_brave
277
local m = {}
@@ -62,11 +42,11 @@ end
6242

6343
--- 开始找工作
6444
function m.start(privatePad)
65-
local reqPad = privatePad and channel_init(channel.query('req:' .. privatePad)) or taskPad
66-
local resPad = privatePad and channel.query('res:' .. privatePad) or waiter
45+
local reqPad = privatePad and thread.channel('req:' .. privatePad) or taskPad
46+
local resPad = privatePad and thread.channel('res:' .. privatePad) or waiter
6747
m.push('mem', collectgarbage 'count')
6848
while true do
69-
local name, id, params = channel_bpop(reqPad)
49+
local name, id, params = reqPad:bpop()
7050
local ability = m.ability[name]
7151
-- TODO
7252
if not ability then

script/pub/pub.lua

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
local thread = require 'bee.thread'
2-
local channel = require 'bee.channel'
3-
local select = require 'bee.select'
42
local utility = require 'utility'
53
local await = require 'await'
64

7-
local function channel_init(chan)
8-
local selector = select.create()
9-
selector:event_add(chan:fd(), select.SELECT_READ)
10-
return { selector, chan }
11-
end
12-
13-
local function channel_bpop(ctx)
14-
local selector, chan = ctx[1], ctx[2]
15-
while true do
16-
for _ in selector:wait() do
17-
local r = table.pack(chan:pop())
18-
if r[1] == true then
19-
return table.unpack(r, 2)
20-
end
21-
end
22-
end
23-
end
5+
thread.newchannel 'taskpad'
6+
thread.newchannel 'waiter'
247

25-
local taskPad = channel.create 'taskpad'
26-
local waiter = channel_init(channel.create 'waiter')
8+
local errLog = thread.channel 'errlog'
9+
local taskPad = thread.channel 'taskpad'
10+
local waiter = thread.channel 'waiter'
2711
local type = type
2812
local counter = utility.counter()
2913

@@ -82,9 +66,11 @@ function m.recruitBraves(num, privatePad)
8266
}
8367
end
8468
if privatePad and not m.prvtPad[privatePad] then
69+
thread.newchannel('req:' .. privatePad)
70+
thread.newchannel('res:' .. privatePad)
8571
m.prvtPad[privatePad] = {
86-
req = channel.create('req:' .. privatePad),
87-
res = channel.create('res:' .. privatePad),
72+
req = thread.channel('req:' .. privatePad),
73+
res = thread.channel('res:' .. privatePad),
8874
}
8975
end
9076
end
@@ -180,7 +166,7 @@ end
180166
--- 接收反馈
181167
function m.recieve(block)
182168
if block then
183-
local id, name, result = channel_bpop(waiter)
169+
local id, name, result = waiter:bpop()
184170
if type(name) == 'string' then
185171
m.popReport(m.braves[id], name, result)
186172
else
@@ -189,7 +175,7 @@ function m.recieve(block)
189175
else
190176
while true do
191177
local ok
192-
if m.reciveFromPad(waiter[2]) then
178+
if m.reciveFromPad(waiter) then
193179
ok = true
194180
end
195181
for _, pad in pairs(m.prvtPad) do
@@ -208,7 +194,7 @@ end
208194
--- 检查伤亡情况
209195
function m.checkDead()
210196
while true do
211-
local suc, err = thread.errlog()
197+
local suc, err = errLog:pop()
212198
if not suc then
213199
break
214200
end

0 commit comments

Comments
 (0)