mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
add coroutine close for skynetco (#1392)
Co-authored-by: jietao.cjt <jietao.cjt@alibaba-inc.com>
This commit is contained in:
@@ -6,6 +6,7 @@ local coroutine_resume = coroutine.resume
|
|||||||
local coroutine_yield = coroutine.yield
|
local coroutine_yield = coroutine.yield
|
||||||
local coroutine_status = coroutine.status
|
local coroutine_status = coroutine.status
|
||||||
local coroutine_running = coroutine.running
|
local coroutine_running = coroutine.running
|
||||||
|
local coroutine_close = coroutine.close
|
||||||
|
|
||||||
local select = select
|
local select = select
|
||||||
local skynetco = {}
|
local skynetco = {}
|
||||||
@@ -15,6 +16,9 @@ skynetco.running = coroutine.running
|
|||||||
skynetco.status = coroutine.status
|
skynetco.status = coroutine.status
|
||||||
|
|
||||||
local skynet_coroutines = setmetatable({}, { __mode = "kv" })
|
local skynet_coroutines = setmetatable({}, { __mode = "kv" })
|
||||||
|
-- true : skynet coroutine
|
||||||
|
-- false : skynet suspend
|
||||||
|
-- nil : exit
|
||||||
|
|
||||||
function skynetco.create(f)
|
function skynetco.create(f)
|
||||||
local co = coroutine.create(f)
|
local co = coroutine.create(f)
|
||||||
@@ -84,7 +88,7 @@ do -- begin skynetco.resume
|
|||||||
end -- end of skynetco.resume
|
end -- end of skynetco.resume
|
||||||
|
|
||||||
function skynetco.status(co)
|
function skynetco.status(co)
|
||||||
local status = coroutine.status(co)
|
local status = coroutine_status(co)
|
||||||
if status == "suspended" then
|
if status == "suspended" then
|
||||||
if skynet_coroutines[co] == false then
|
if skynet_coroutines[co] == false then
|
||||||
return "blocked"
|
return "blocked"
|
||||||
@@ -121,4 +125,9 @@ end
|
|||||||
|
|
||||||
end -- end of skynetco.wrap
|
end -- end of skynetco.wrap
|
||||||
|
|
||||||
|
function skynetco.close(co)
|
||||||
|
skynet_coroutines[co] = nil
|
||||||
|
return coroutine_close(co)
|
||||||
|
end
|
||||||
|
|
||||||
return skynetco
|
return skynetco
|
||||||
|
|||||||
@@ -50,4 +50,5 @@ skynet.start(function()
|
|||||||
print("main step", f())
|
print("main step", f())
|
||||||
print("main step", f())
|
print("main step", f())
|
||||||
-- print("main thread time:", profile.stop())
|
-- print("main thread time:", profile.stop())
|
||||||
|
print("close", coroutine.close(coroutine.create(main)))
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user