From 8203564f88be814227d2ea88d67c0cbd97987f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 9 Feb 2021 16:59:21 +0800 Subject: some fix --- script/brave/brave.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'script/brave') diff --git a/script/brave/brave.lua b/script/brave/brave.lua index c5ad733b..36b56b54 100644 --- a/script/brave/brave.lua +++ b/script/brave/brave.lua @@ -1,5 +1,8 @@ local thread = require 'bee.thread' +local taskPad = thread.channel('taskpad') +local waiter = thread.channel('waiter') + ---@class pub_brave local m = {} m.type = 'brave' @@ -8,13 +11,11 @@ m.queue = {} --- 注册成为勇者 function m.register(id) - m.taskpad = thread.channel('taskpad' .. id) - m.waiter = thread.channel('waiter' .. id) - m.id = id + m.id = id if #m.queue > 0 then for _, info in ipairs(m.queue) do - m.waiter:push(m.id, info.name, info.params) + waiter:push(m.id, info.name, info.params) end end m.queue = nil @@ -29,8 +30,8 @@ end --- 报告 function m.push(name, params) - if m.waiter then - m.waiter:push(m.id, name, params) + if m.id then + waiter:push(m.id, name, params) else m.queue[#m.queue+1] = { name = name, @@ -43,19 +44,19 @@ end function m.start() m.push('mem', collectgarbage 'count') while true do - local name, id, params = m.taskpad:bpop() + local name, id, params = taskPad:bpop() local ability = m.ability[name] -- TODO if not ability then - m.waiter:push(m.id, id) + waiter: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 - m.waiter:push(m.id, id, res) + waiter:push(m.id, id, res) else - m.waiter:push(m.id, id) + waiter:push(m.id, id) end m.push('mem', collectgarbage 'count') ::CONTINUE:: -- cgit debian/1.2.3+git2.25.1-1-2-gaceb0