mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
skynet.service: add close (#1526)
Co-authored-by: drew.zxj <drew.zxj@alibaba-inc.com>
This commit is contained in:
@@ -34,6 +34,16 @@ function service.new(name, mainfunc, ...)
|
|||||||
return address
|
return address
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function service.close(name)
|
||||||
|
local addr = skynet.call(get_provider(), "lua", "close", name)
|
||||||
|
if addr then
|
||||||
|
cache[name] = nil
|
||||||
|
skynet.kill(addr)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function service.query(name)
|
function service.query(name)
|
||||||
if not cache[name] then
|
if not cache[name] then
|
||||||
cache[name] = skynet.call(get_provider(), "lua", "query", name)
|
cache[name] = skynet.call(get_provider(), "lua", "query", name)
|
||||||
|
|||||||
@@ -91,6 +91,16 @@ function provider.test(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function provider.close(name)
|
||||||
|
local s = svr[name]
|
||||||
|
if not s or s.booting then
|
||||||
|
return skynet.ret(skynet.pack(nil))
|
||||||
|
end
|
||||||
|
|
||||||
|
svr[name] = nil
|
||||||
|
skynet.ret(skynet.pack(s.address))
|
||||||
|
end
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
skynet.dispatch("lua", function(session, address, cmd, ...)
|
skynet.dispatch("lua", function(session, address, cmd, ...)
|
||||||
provider[cmd](...)
|
provider[cmd](...)
|
||||||
|
|||||||
Reference in New Issue
Block a user