Skip to content

Commit

Permalink
Use fork instead of timeout 0, see cloudwu#873
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Aug 7, 2018
1 parent d2ab686 commit 281acf4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lualib/skynet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function suspend(co, result, command, param, param2)
session_coroutine_address[co] = nil
session_coroutine_tracetag[co] = nil
end
skynet.timeout(0,function() end) -- trigger command "SUSPEND"
skynet.fork(function() end) -- trigger command "SUSPEND"
error(debug.traceback(co,tostring(command)))
end
if command == "SUSPEND" then
Expand Down Expand Up @@ -540,10 +540,14 @@ function skynet.dispatch_unknown_response(unknown)
end

function skynet.fork(func,...)
local args = table.pack(...)
local co = co_create(function()
func(table.unpack(args,1,args.n))
end)
local n = select("#", ...)
local co
if n == 0 then
co = co_create(func)
else
local args = { ... }
co = co_create(function() func(table.unpack(args,1,n)) end)
end
table.insert(fork_queue, co)
return co
end
Expand Down

0 comments on commit 281acf4

Please sign in to comment.