summaryrefslogtreecommitdiff
path: root/script/proto
diff options
context:
space:
mode:
Diffstat (limited to 'script/proto')
-rw-r--r--script/proto/define.lua1
-rw-r--r--script/proto/proto.lua15
2 files changed, 13 insertions, 3 deletions
diff --git a/script/proto/define.lua b/script/proto/define.lua
index 731c5cc6..fa351abb 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -173,6 +173,7 @@ m.ErrorCodes = {
UnknownErrorCode = -32001,
-- Defined by the protocol.
+ ContentModified = -32801,
RequestCancelled = -32800,
}
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 61306b9f..7767ec0a 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -116,7 +116,7 @@ function m.doMethod(proto)
return
end
if proto.id then
- m.holdon[proto.id] = method
+ m.holdon[proto.id] = proto
end
await.call(function ()
--log.debug('Start method:', method)
@@ -124,7 +124,7 @@ function m.doMethod(proto)
await.setID('proto:' .. proto.id)
end
local clock = os.clock()
- local ok = true
+ local ok = false
local res
-- 任务可能在执行过程中被中断,通过close来捕获
local response <close> = function ()
@@ -140,13 +140,22 @@ function m.doMethod(proto)
if ok then
m.response(proto.id, res)
else
- m.responseErr(proto.id, define.ErrorCodes.InternalError, res)
+ m.responseErr(proto.id, proto._closeReason or define.ErrorCodes.InternalError, res)
end
end
ok, res = xpcall(abil, log.error, proto.params)
end)
end
+function m.close(id, reason)
+ local proto = m.holdon[id]
+ if not proto then
+ return
+ end
+ proto._closeReason = reason
+ await.close('proto:' .. id)
+end
+
function m.doResponse(proto)
local id = proto.id
local resume = m.waiting[id]