to-be-closed (#1261)

This commit is contained in:
hong
2020-12-01 11:51:35 +08:00
committed by GitHub
parent 5248d443dc
commit 693b962b43
2 changed files with 63 additions and 1 deletions

View File

@@ -14,12 +14,20 @@ local tunpack = table.unpack
local traceback = debug.traceback
local cresume = coroutine.resume
local coroutine_close = coroutine.close
local running_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, ...)
running_thread = co
return cresume(co, ...)
return coroutine_ret(co, cresume(co, ...))
end
local coroutine_yield = coroutine.yield
local coroutine_create = coroutine.create
@@ -329,6 +337,7 @@ function suspend(co, result, command)
if command == "SUSPEND" then
return dispatch_wakeup()
elseif command == "QUIT" then
coroutine_close(co)
-- service exit
return
elseif command == "USER" then
@@ -523,6 +532,11 @@ function skynet.exit()
c.send(address, skynet.PTYPE_ERROR, session, "")
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
resp(false)
end