mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 19:43:09 +00:00
unique service
This commit is contained in:
@@ -17,7 +17,7 @@ function group.release(id)
|
||||
end
|
||||
|
||||
skynet.init(function()
|
||||
lg = skynet.call(".service","lua","group_local")
|
||||
lg = skynet.uniqueservice("group_local")
|
||||
assert(lg)
|
||||
end, "localgroup")
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ function group.release(id)
|
||||
end
|
||||
|
||||
skynet.init(function()
|
||||
SERVICE = skynet.call("SERVICE", "lua", "group_mgr")
|
||||
skynet.call(".service","lua","group_agent", SERVICE)
|
||||
SERVICE = skynet.uniqueservice(true, "group_mgr")
|
||||
skynet.uniqueservice("group_agent", SERVICE)
|
||||
end, "mcgroup")
|
||||
|
||||
return group
|
||||
|
||||
@@ -38,7 +38,7 @@ function redis.connect(dbname)
|
||||
end
|
||||
|
||||
skynet.init(function()
|
||||
redis_manager = skynet.call(".service", "lua", "redis-mgr")
|
||||
redis_manager = skynet.uniqueservice("redis-mgr")
|
||||
end, "redis")
|
||||
|
||||
return redis
|
||||
|
||||
@@ -297,6 +297,23 @@ function skynet.newservice(name, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function skynet.uniqueservice(global, ...)
|
||||
local t = 0
|
||||
while true do
|
||||
local handle
|
||||
if global == true then
|
||||
handle = skynet.call("SERVICE", "lua", ...)
|
||||
else
|
||||
handle = skynet.call(".service", "lua", global, ...)
|
||||
end
|
||||
if handle then
|
||||
return handle
|
||||
end
|
||||
skynet.sleep(t)
|
||||
t=t+1
|
||||
end
|
||||
end
|
||||
|
||||
local function group_command(cmd, handle, address)
|
||||
if address then
|
||||
return string.format("%s %d :%x",cmd, handle, address)
|
||||
|
||||
@@ -5,6 +5,7 @@ local service = {}
|
||||
local function query(service_name, ...)
|
||||
local s = service[service_name]
|
||||
if s == nil then
|
||||
service[service_name] = false
|
||||
s = skynet.newservice(service_name, ...)
|
||||
service[service_name] = s
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user