mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
skynet.coroutine.status may return blocked
This commit is contained in:
@@ -80,6 +80,19 @@ end
|
||||
|
||||
end -- end of skynetco.resume
|
||||
|
||||
function skynetco.status(co)
|
||||
local status = coroutine.status(co)
|
||||
if status == "suspended" then
|
||||
if skynet_coroutines[co] == false then
|
||||
return "blocked"
|
||||
else
|
||||
return "suspended"
|
||||
end
|
||||
else
|
||||
return status
|
||||
end
|
||||
end
|
||||
|
||||
function skynetco.yield(...)
|
||||
return coroutine_yield("USER", ...)
|
||||
end
|
||||
|
||||
@@ -2,23 +2,37 @@ local skynet = require "skynet"
|
||||
-- You should use skynet.coroutine instead of origin coroutine in skynet
|
||||
local coroutine = require "skynet.coroutine"
|
||||
|
||||
local function status(co)
|
||||
repeat
|
||||
local status = coroutine.status(co)
|
||||
print("STATUS", status)
|
||||
skynet.sleep(100)
|
||||
until status == "suspended"
|
||||
|
||||
repeat
|
||||
local ok, n = assert(coroutine.resume(co))
|
||||
print("status thread", n)
|
||||
until not n
|
||||
skynet.exit()
|
||||
end
|
||||
|
||||
local function test(n)
|
||||
print ("begin", coroutine.isskynetcoroutine())
|
||||
local co = coroutine.running()
|
||||
print ("begin", coroutine.isskynetcoroutine(co))
|
||||
skynet.fork(status, co)
|
||||
for i=1,n do
|
||||
skynet.sleep(100)
|
||||
coroutine.yield(i)
|
||||
end
|
||||
print "end"
|
||||
return false
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
print("Is the main thead a skynet coroutine ?", coroutine.isskynetcoroutine(coroutine.running())) -- always false
|
||||
print("Is the main thead a skynet coroutine ?", coroutine.isskynetcoroutine()) -- always false
|
||||
print(coroutine.resume(coroutine.running())) -- always return false
|
||||
local f = coroutine.wrap(test)
|
||||
repeat
|
||||
for i=1,3 do
|
||||
local n = f(5)
|
||||
print(n)
|
||||
until not n
|
||||
skynet.exit()
|
||||
print("main thread",n)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user