skynet.wait use token instead of coroutine.running()

This commit is contained in:
Cloud Wu
2018-05-25 10:42:58 +08:00
parent 2fde0a0ae4
commit 348e53245b
2 changed files with 30 additions and 26 deletions

View File

@@ -14,18 +14,15 @@ local function test_service()
end
local function timeout_call(ti, ...)
local co = coroutine.running()
local token = {}
local ret
skynet.fork(function(...)
ret = table.pack(pcall(skynet.call, ...))
if co then
skynet.wakeup(co)
end
skynet.wakeup(token)
end, ...)
skynet.sleep(ti)
co = nil -- prevent wakeup after call
skynet.sleep(ti, token)
if ret then
if ret[1] then
return table.unpack(ret, 1, ret.n)
@@ -45,6 +42,8 @@ skynet.start(function()
skynet.error("2", skynet.now())
skynet.error(timeout_call(50, test, "lua"))
skynet.error("3", skynet.now())
skynet.error(timeout_call(150, test, "lua"))
skynet.error("4", skynet.now())
skynet.exit()
end)