summaryrefslogtreecommitdiff
path: root/server-beta/src/pub/brave.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/pub/brave.lua')
-rw-r--r--server-beta/src/pub/brave.lua22
1 files changed, 19 insertions, 3 deletions
diff --git a/server-beta/src/pub/brave.lua b/server-beta/src/pub/brave.lua
index c9fd0afe..7662a39e 100644
--- a/server-beta/src/pub/brave.lua
+++ b/server-beta/src/pub/brave.lua
@@ -5,7 +5,23 @@ local m = {}
m.type = 'pub.brave'
--- 注册成为勇者
-function m:register(id)
- self.taskpad = thread.channel('taskpad' .. id)
- self.waiter = thread.channel('waiter' .. id)
+function m.register(id)
+ m.taskpad = thread.channel('taskpad' .. id)
+ m.waiter = thread.channel('waiter' .. id)
+ m.start()
end
+
+--- 开始找工作
+function m.start()
+ while true do
+ local suc, name, id, params = m.taskpad:pop()
+ if not suc then
+ -- 找不到工作的勇者,只好睡觉
+ thread.sleep(0.01)
+ end
+ local result = require(name)(params)
+ m.waiter:push(id, result)
+ end
+end
+
+return m