11local thread = require ' bee.thread'
2- local channel = require ' bee.channel'
3- local select = require ' bee.select'
42local utility = require ' utility'
53local 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'
2711local type = type
2812local 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
9076end
180166--- 接收反馈
181167function 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
208194--- 检查伤亡情况
209195function 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