bugfix:cluster初始化节点的时候有可能导致消息乱序

This commit is contained in:
hong
2019-04-17 11:18:51 +08:00
committed by 云风
parent 4c17005c03
commit 9ba0860c70

View File

@@ -3,11 +3,26 @@ local skynet = require "skynet"
local clusterd
local cluster = {}
local sender = {}
local inquery_name = {}
local function get_sender(t, node)
local c = skynet.call(clusterd, "lua", "sender", node)
t[node] = c
return c
local waitco = inquery_name[node]
if waitco then
local co=coroutine.running()
table.insert(waitco, co)
skynet.wait(co)
return rawget(t, node)
else
waitco = {}
inquery_name[node] = waitco
local c = skynet.call(clusterd, "lua", "sender", node)
inquery_name[node] = nil
t[node] = c
for _, co in ipairs(waitco) do
skynet.wakeup(co)
end
return c
end
end
setmetatable(sender, { __index = get_sender } )