summaryrefslogtreecommitdiff
path: root/script-beta/proto/proto.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/proto/proto.lua')
-rw-r--r--script-beta/proto/proto.lua18
1 files changed, 15 insertions, 3 deletions
diff --git a/script-beta/proto/proto.lua b/script-beta/proto/proto.lua
index af0515ec..7b6b0087 100644
--- a/script-beta/proto/proto.lua
+++ b/script-beta/proto/proto.lua
@@ -4,6 +4,7 @@ local await = require 'await'
local pub = require 'pub'
local jsonrpc = require 'jsonrpc'
local ErrorCodes = require 'define.ErrorCodes'
+local timer = require 'timer'
local reqCounter = util.counter()
@@ -11,6 +12,7 @@ local m = {}
m.ability = {}
m.waiting = {}
+m.running = {}
function m.getMethodName(proto)
if proto.method:sub(1, 2) == '$/' then
@@ -89,10 +91,16 @@ function m.doMethod(proto)
end
return
end
+ if proto.id then
+ m.running[proto.id] = method
+ end
await.create(function ()
log.debug('Start method:', method)
- local ok, res, passed
+ local clock = os.clock()
+ local ok, res
+ -- 任务可能在执行过程中被中断,通过close来捕获
local response <close> = util.defer(function ()
+ local passed = os.clock() - clock
if passed > 0.2 then
log.debug(('Method [%s] takes [%.3f]sec.'):format(method, passed))
end
@@ -105,10 +113,9 @@ function m.doMethod(proto)
else
m.responseErr(proto.id, ErrorCodes.InternalError, res)
end
+ m.running[proto.id] = nil
end)
- local clock = os.clock()
ok, res = xpcall(abil, log.error, proto.params)
- passed = os.clock() - clock
end)
end
@@ -133,6 +140,11 @@ function m.listen()
io.stdin:setvbuf 'no'
io.stdout:setvbuf 'no'
pub.task('loadProto')
+ timer.loop(10, function ()
+ for id, name in pairs(m.running) do
+ m.responseErr(id, ErrorCodes.InternalError, ('Task [%s] failed unexpected!'):format(name))
+ end
+ end)
end
return m