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