mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
to-be-closed (#1261)
This commit is contained in:
@@ -14,12 +14,20 @@ local tunpack = table.unpack
|
|||||||
local traceback = debug.traceback
|
local traceback = debug.traceback
|
||||||
|
|
||||||
local cresume = coroutine.resume
|
local cresume = coroutine.resume
|
||||||
|
local coroutine_close = coroutine.close
|
||||||
local running_thread = nil
|
local running_thread = nil
|
||||||
local init_thread = nil
|
local init_thread = nil
|
||||||
|
|
||||||
|
local function coroutine_ret(co, ok, ...)
|
||||||
|
if not ok then
|
||||||
|
coroutine_close(co)
|
||||||
|
end
|
||||||
|
return ok, ...
|
||||||
|
end
|
||||||
|
|
||||||
local function coroutine_resume(co, ...)
|
local function coroutine_resume(co, ...)
|
||||||
running_thread = co
|
running_thread = co
|
||||||
return cresume(co, ...)
|
return coroutine_ret(co, cresume(co, ...))
|
||||||
end
|
end
|
||||||
local coroutine_yield = coroutine.yield
|
local coroutine_yield = coroutine.yield
|
||||||
local coroutine_create = coroutine.create
|
local coroutine_create = coroutine.create
|
||||||
@@ -329,6 +337,7 @@ function suspend(co, result, command)
|
|||||||
if command == "SUSPEND" then
|
if command == "SUSPEND" then
|
||||||
return dispatch_wakeup()
|
return dispatch_wakeup()
|
||||||
elseif command == "QUIT" then
|
elseif command == "QUIT" then
|
||||||
|
coroutine_close(co)
|
||||||
-- service exit
|
-- service exit
|
||||||
return
|
return
|
||||||
elseif command == "USER" then
|
elseif command == "USER" then
|
||||||
@@ -523,6 +532,11 @@ function skynet.exit()
|
|||||||
c.send(address, skynet.PTYPE_ERROR, session, "")
|
c.send(address, skynet.PTYPE_ERROR, session, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for session, co in pairs(session_id_coroutine) do
|
||||||
|
if type(co) == "thread" then
|
||||||
|
coroutine_close(co)
|
||||||
|
end
|
||||||
|
end
|
||||||
for resp in pairs(unresponse) do
|
for resp in pairs(unresponse) do
|
||||||
resp(false)
|
resp(false)
|
||||||
end
|
end
|
||||||
|
|||||||
48
test/testtobeclosed.lua
Normal file
48
test/testtobeclosed.lua
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
local skynet = require "skynet"
|
||||||
|
|
||||||
|
local function new_test(name)
|
||||||
|
return setmetatable({}, { __close = function(...)
|
||||||
|
skynet.error(...)
|
||||||
|
end, __name = "closemeta:" .. name})
|
||||||
|
end
|
||||||
|
|
||||||
|
local i = 0
|
||||||
|
skynet.dispatch("lua", function()
|
||||||
|
i = i + 1
|
||||||
|
if i==2 then
|
||||||
|
local c<close> = new_test("dispatch_error")
|
||||||
|
error("dispatch_error")
|
||||||
|
else
|
||||||
|
local c<close> = new_test("dispatch_wait")
|
||||||
|
skynet.wait()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
skynet.start(function()
|
||||||
|
local c<close> = new_test("skynet.exit")
|
||||||
|
skynet.fork(function()
|
||||||
|
local a<close> = new_test("stack_raise_error")
|
||||||
|
error("raise error")
|
||||||
|
end)
|
||||||
|
skynet.fork(function()
|
||||||
|
local a<close> = new_test("session_id_coroutine_wait")
|
||||||
|
skynet.wait()
|
||||||
|
end)
|
||||||
|
skynet.fork(function()
|
||||||
|
local a<close> = new_test("session_id_coroutine_call")
|
||||||
|
skynet.call(skynet.self(), "lua")
|
||||||
|
end)
|
||||||
|
skynet.fork(function()
|
||||||
|
skynet.call(skynet.self(), "lua")
|
||||||
|
end)
|
||||||
|
skynet.sleep(100)
|
||||||
|
skynet.fork(function()
|
||||||
|
local a<close> = new_test("no_running")
|
||||||
|
skynet.wait()
|
||||||
|
end)
|
||||||
|
skynet.exit()
|
||||||
|
end)
|
||||||
|
|
||||||
|
--[[
|
||||||
|
testtobeclosed
|
||||||
|
]]
|
||||||
Reference in New Issue
Block a user