diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/brave/brave.lua | 11 | ||||
-rw-r--r-- | script/pub/pub.lua | 41 |
2 files changed, 37 insertions, 15 deletions
diff --git a/script/brave/brave.lua b/script/brave/brave.lua index f07fb00f..9ad7ebd1 100644 --- a/script/brave/brave.lua +++ b/script/brave/brave.lua @@ -42,22 +42,23 @@ end --- 开始找工作 function m.start(privatePad) - local myPad = privatePad and thread.channel('private:' .. privatePad) or taskPad + 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 = myPad:bpop() + local name, id, params = reqPad:bpop() local ability = m.ability[name] -- TODO if not ability then - waiter:push(m.id, id) + resPad:push(m.id, id) log.error('Brave can not handle this work: ' .. name) goto CONTINUE end local ok, res = xpcall(ability, log.error, params) if ok then - waiter:push(m.id, id, res) + resPad:push(m.id, id, res) else - waiter:push(m.id, id) + resPad:push(m.id, id) end m.push('mem', collectgarbage 'count') ::CONTINUE:: diff --git a/script/pub/pub.lua b/script/pub/pub.lua index 9733846a..5bbb381c 100644 --- a/script/pub/pub.lua +++ b/script/pub/pub.lua @@ -66,8 +66,12 @@ function m.recruitBraves(num, privatePad) } end if privatePad and not m.prvtPad[privatePad] then - thread.newchannel('private:' .. privatePad) - m.prvtPad[privatePad] = thread.channel('private:' .. privatePad) + thread.newchannel('req:' .. privatePad) + thread.newchannel('res:' .. privatePad) + m.prvtPad[privatePad] = { + req = thread.channel('req:' .. privatePad), + res = thread.channel('res:' .. privatePad), + } end end @@ -77,7 +81,7 @@ function m.pushTask(info) return false end if m.prvtPad[info.name] then - m.prvtPad[info.name]:push(info.name, info.id, info.params) + m.prvtPad[info.name].req:push(info.name, info.id, info.params) else taskPad:push(info.name, info.id, info.params) end @@ -146,6 +150,19 @@ function m.task(name, params, callback) return m.pushTask(info) end +function m.reciveFromPad(pad) + local suc, id, name, result = pad:pop() + if not suc then + return false + end + if type(name) == 'string' then + m.popReport(m.braves[id], name, result) + else + m.popTask(m.braves[id], name, result) + end + return true +end + --- 接收反馈 function m.recieve(block) if block then @@ -157,14 +174,18 @@ function m.recieve(block) end else while true do - local suc, id, name, result = waiter:pop() - if not suc then - break + local ok + if m.reciveFromPad(waiter) then + ok = true end - if type(name) == 'string' then - m.popReport(m.braves[id], name, result) - else - m.popTask(m.braves[id], name, result) + for _, pad in pairs(m.prvtPad) do + if m.reciveFromPad(pad.res) then + ok = true + end + end + + if not ok then + break end end end |