mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 19:43:09 +00:00
make service mgr simple
This commit is contained in:
@@ -414,8 +414,8 @@ function skynet.uniqueservice(...)
|
||||
return assert(skynet.call(".service", "lua", "LAUNCH", ...))
|
||||
end
|
||||
|
||||
function skynet.queryservice(global, name)
|
||||
return assert(skynet.call(".service", "lua", "QUERY", global, name))
|
||||
function skynet.queryservice(...)
|
||||
return assert(skynet.call(".service", "lua", "QUERY", ...))
|
||||
end
|
||||
|
||||
local function group_command(cmd, handle, address)
|
||||
|
||||
@@ -57,49 +57,34 @@ local function waitfor(name , func, ...)
|
||||
return s
|
||||
end
|
||||
|
||||
local function GQUERY(service_name)
|
||||
if GLOBAL then
|
||||
return cmd.QUERY(service_name)
|
||||
else
|
||||
return waitfor(service_name, skynet.call, "SERVICE", "lua", "QUERY", service_name)
|
||||
end
|
||||
function cmd.LAUNCH(service_name, ...)
|
||||
return waitfor(service_name, skynet.newservice, service_name, ...)
|
||||
end
|
||||
|
||||
local function GLAUNCH(service_name, ...)
|
||||
if GLOBAL then
|
||||
return cmd.LAUNCH(service_name, ...)
|
||||
else
|
||||
return waitfor(service_name, skynet.call, "SERVICE", "lua", "LAUNCH", service_name, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function cmd.LAUNCH(global, service_name, ...)
|
||||
if global == true then
|
||||
return GLAUNCH(service_name, ...)
|
||||
else
|
||||
assert(type(global) == "string")
|
||||
return waitfor(global, skynet.newservice, global, service_name, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function cmd.QUERY(global, service_name)
|
||||
if global == true then
|
||||
return GQUERY(service_name)
|
||||
else
|
||||
assert(type(global) == "string")
|
||||
return waitfor(global)
|
||||
end
|
||||
function cmd.QUERY(service_name)
|
||||
return waitfor(service_name)
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua", function(session, address, command, service_name , ...)
|
||||
skynet.dispatch("lua", function(session, address, command, global, service_name , ...)
|
||||
local f = cmd[command]
|
||||
if f == nil then
|
||||
skynet.ret(skynet.pack(nil))
|
||||
skynet.ret(skynet.pack(nil, "Invalid command " .. command))
|
||||
return
|
||||
end
|
||||
|
||||
local ok, r = pcall(f, service_name, ...)
|
||||
local ok, r
|
||||
if global == true then
|
||||
if GLOBAL then
|
||||
ok, r = pcall(f, service_name, ...)
|
||||
else
|
||||
return waitfor(service_name, skynet.call, "SERVICE", "lua", command, service_name, ...)
|
||||
end
|
||||
else
|
||||
assert(type(global) == "string") -- global is service_name
|
||||
ok, r = pcall(f, global, service_name, ...)
|
||||
end
|
||||
|
||||
if ok then
|
||||
skynet.ret(skynet.pack(r))
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user