summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server-beta/main.lua3
-rw-r--r--server-beta/src/pub/client.lua46
-rw-r--r--server-beta/src/service.lua7
-rw-r--r--server-beta/src/task.lua3
4 files changed, 32 insertions, 27 deletions
diff --git a/server-beta/main.lua b/server-beta/main.lua
index 32fb213c..d102658c 100644
--- a/server-beta/main.lua
+++ b/server-beta/main.lua
@@ -11,8 +11,7 @@ log = require 'log'
log.init(ROOT, ROOT / 'log' / 'service.log')
log.info('Lua Lsp startup, root: ', ROOT)
log.debug('ROOT:', ROOT:string())
-ac = {}
-xpcall(dofile, log.debug, rootPath .. '/debugger.lua')
+--xpcall(dofile, log.debug, rootPath .. '/debugger.lua')
local service = require 'service'
service.start()
diff --git a/server-beta/src/pub/client.lua b/server-beta/src/pub/client.lua
index 8840b56a..2aec2593 100644
--- a/server-beta/src/pub/client.lua
+++ b/server-beta/src/pub/client.lua
@@ -1,12 +1,16 @@
local thread = require 'bee.thread'
local utility = require 'utility'
local task = require 'task'
-local type = require 'type'
+
+local errLog = thread.channel 'errlog'
+local type = type
local braveTemplate = [[
package.path = %q
package.cpath = %q
+--log = require 'work.log'
+
local brave = require 'pub.brave'
brave.register(%d)
]]
@@ -21,7 +25,7 @@ m.braves = {}
function m.recruitBraves(num)
for _ = 1, num do
local id = #m.braves + 1
- log.info('Create pub brave:', id)
+ log.info('Create brave:', id)
thread.newchannel('taskpad' .. id)
thread.newchannel('waiter' .. id)
m.braves[id] = {
@@ -83,28 +87,30 @@ end
---|返回接收到的反馈数量
---@return integer
function m.recieve()
- local count = 0
- while true do
- local hasRecived = false
- for _, brave in ipairs(m.braves) do
- local suc, id, result = brave.waiter:pop()
- if not suc then
- goto CONTINUE
- end
- count = count + 1
- hasRecived = true
- if type(id) == 'string' then
- m.popTask(brave, id, result)
- else
- m.popReport(brave, id, result)
- end
- ::CONTINUE::
+ for _, brave in ipairs(m.braves) do
+ local suc, id, result = brave.waiter:pop()
+ if not suc then
+ goto CONTINUE
+ end
+ if type(id) == 'string' then
+ m.popTask(brave, id, result)
+ else
+ m.popReport(brave, id, result)
end
- if not hasRecived then
+ task.sleep(0)
+ ::CONTINUE::
+ end
+end
+
+--- 检查伤亡情况
+function m.checkDead()
+ while true do
+ local suc, err = errLog:pop()
+ if not suc then
break
end
+ log.error('Brave is dead!: ' .. err)
end
- return count
end
return m
diff --git a/server-beta/src/service.lua b/server-beta/src/service.lua
index 650fe558..bd217627 100644
--- a/server-beta/src/service.lua
+++ b/server-beta/src/service.lua
@@ -24,10 +24,9 @@ end
function m.listenPub()
task.create(function ()
while true do
- local count = client.recieve()
- if count == 0 then
- task.sleep(0.001)
- end
+ client.checkDead()
+ client.recieve()
+ task.sleep(0)
end
end)
end
diff --git a/server-beta/src/task.lua b/server-beta/src/task.lua
index 264e2ac5..9219a6a2 100644
--- a/server-beta/src/task.lua
+++ b/server-beta/src/task.lua
@@ -12,7 +12,8 @@ end
--- 创建一个任务
function m.create(callback)
- coroutine.create(callback)
+ local co = coroutine.create(callback)
+ coroutine.resume(co)
end
--- 休眠一段时间