mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add service manager
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
local skynet = require "skynet"
|
||||
|
||||
local SERVICE = "GROUPMGR"
|
||||
local SERVICE
|
||||
|
||||
local group = {}
|
||||
|
||||
@@ -27,4 +27,9 @@ function group.release(id)
|
||||
skynet.send(SERVICE, "lua" , "CLEAR", skynet.self(), id)
|
||||
end
|
||||
|
||||
skynet.init(function()
|
||||
SERVICE = skynet.call("SERVICE", "lua", "group_mgr")
|
||||
skynet.call(".service","lua","group_agent")
|
||||
end, "group")
|
||||
|
||||
return group
|
||||
@@ -3,6 +3,8 @@ local string = string
|
||||
local table = table
|
||||
local unpack = unpack
|
||||
|
||||
local redis_manager
|
||||
|
||||
local redis = {}
|
||||
|
||||
local command = {}
|
||||
@@ -30,9 +32,13 @@ local meta = {
|
||||
}
|
||||
|
||||
function redis.connect(dbname)
|
||||
local handle = skynet.call(".redis-manager", "lua", dbname)
|
||||
local handle = skynet.call(redis_manager, "lua", dbname)
|
||||
assert(handle ~= nil)
|
||||
return setmetatable({ __handle = handle } , meta)
|
||||
end
|
||||
|
||||
skynet.init(function()
|
||||
redis_manager = skynet.call(".service", "lua", "redis-mgr")
|
||||
end, "redis")
|
||||
|
||||
return redis
|
||||
|
||||
@@ -402,9 +402,34 @@ do
|
||||
}
|
||||
end
|
||||
|
||||
local init_func = {}
|
||||
|
||||
function skynet.init(f, name)
|
||||
assert(type(f) == "function")
|
||||
if init_func == nil then
|
||||
f()
|
||||
else
|
||||
if name == nil then
|
||||
table.insert(init_func, f)
|
||||
else
|
||||
assert(init_func[name] == nil)
|
||||
init_func[name] = f
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function init_all()
|
||||
local funcs = init_func
|
||||
init_func = nil
|
||||
for k,v in pairs(funcs) do
|
||||
v()
|
||||
end
|
||||
end
|
||||
|
||||
function skynet.start(f)
|
||||
c.callback(dispatch_message)
|
||||
skynet.timeout(0, function()
|
||||
init_all()
|
||||
f()
|
||||
skynet.send(".launcher","lua", nil)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user