mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
change name from pub/subscribe to post/accept
This commit is contained in:
@@ -14,7 +14,7 @@ function snax.interface(name)
|
|||||||
local si = snax_interface(name, G)
|
local si = snax_interface(name, G)
|
||||||
|
|
||||||
local ret = {
|
local ret = {
|
||||||
subscribe = {},
|
accept = {},
|
||||||
response = {},
|
response = {},
|
||||||
system = {},
|
system = {},
|
||||||
}
|
}
|
||||||
@@ -33,10 +33,10 @@ local meta = { __tostring = function(v) return string.format("[%s:%x]", v.type,
|
|||||||
local skynet_send = skynet.send
|
local skynet_send = skynet.send
|
||||||
local skynet_call = skynet.call
|
local skynet_call = skynet.call
|
||||||
|
|
||||||
local function gen_pub(type, handle)
|
local function gen_post(type, handle)
|
||||||
return setmetatable({} , {
|
return setmetatable({} , {
|
||||||
__index = function( t, k )
|
__index = function( t, k )
|
||||||
local id = assert(type.subscribe[k] , string.format("publish %s no exist", k))
|
local id = assert(type.accept[k] , string.format("post %s no exist", k))
|
||||||
return function(...)
|
return function(...)
|
||||||
skynet_send(handle, "lua", id, ...)
|
skynet_send(handle, "lua", id, ...)
|
||||||
end
|
end
|
||||||
@@ -55,7 +55,7 @@ end
|
|||||||
|
|
||||||
local function wrapper(handle, name, type)
|
local function wrapper(handle, name, type)
|
||||||
return setmetatable ({
|
return setmetatable ({
|
||||||
pub = gen_pub(type, handle),
|
post = gen_post(type, handle),
|
||||||
req = gen_req(type, handle),
|
req = gen_req(type, handle),
|
||||||
type = name,
|
type = name,
|
||||||
handle = handle,
|
handle = handle,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ return function (name , G, loader)
|
|||||||
assert(G.init == nil)
|
assert(G.init == nil)
|
||||||
assert(G.exit == nil)
|
assert(G.exit == nil)
|
||||||
|
|
||||||
assert(G.subscribe == nil)
|
assert(G.accept == nil)
|
||||||
assert(G.response == nil)
|
assert(G.response == nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ return function (name , G, loader)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
env.subscribe = func_id(func, "subscribe")
|
env.accept = func_id(func, "accept")
|
||||||
env.response = func_id(func, "response")
|
env.response = func_id(func, "response")
|
||||||
|
|
||||||
local function init_system(t, name, f)
|
local function init_system(t, name, f)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ local function message_dispatch()
|
|||||||
local method = msg.method
|
local method = msg.method
|
||||||
local f = method[4]
|
local f = method[4]
|
||||||
if f then
|
if f then
|
||||||
if method[2] == "subscribe" then
|
if method[2] == "accept" then
|
||||||
-- no return
|
-- no return
|
||||||
local ok, data = pcall(f, table.unpack(msg))
|
local ok, data = pcall(f, table.unpack(msg))
|
||||||
if not ok then
|
if not ok then
|
||||||
@@ -94,7 +94,7 @@ skynet.start(function()
|
|||||||
assert(init, "Init first")
|
assert(init, "Init first")
|
||||||
if mode == "queue" then
|
if mode == "queue" then
|
||||||
queue(session, source, method , ...)
|
queue(session, source, method , ...)
|
||||||
elseif method[2] == "subscribe" then
|
elseif method[2] == "accept" then
|
||||||
-- no return
|
-- no return
|
||||||
method[4](...)
|
method[4](...)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ function response.ping(hello)
|
|||||||
return hello
|
return hello
|
||||||
end
|
end
|
||||||
|
|
||||||
function subscribe.hello()
|
function accept.hello()
|
||||||
i = i + 1
|
i = i + 1
|
||||||
print (i, hello)
|
print (i, hello)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ local snax = require "snax"
|
|||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
local ps = snax.newservice ("pingserver", "hello world")
|
local ps = snax.newservice ("pingserver", "hello world")
|
||||||
print(ps.req.ping("foobar"))
|
print(ps.req.ping("foobar"))
|
||||||
print(ps.pub.hello())
|
print(ps.post.hello())
|
||||||
print(pcall(ps.req.error))
|
print(pcall(ps.req.error))
|
||||||
print("Hotfix (i) :", snax.hotfix(ps, [[
|
print("Hotfix (i) :", snax.hotfix(ps, [[
|
||||||
|
|
||||||
local i
|
local i
|
||||||
local hello
|
local hello
|
||||||
|
|
||||||
function subscribe.hello()
|
function accept.hello()
|
||||||
i = i + 1
|
i = i + 1
|
||||||
print ("fix", i, hello)
|
print ("fix", i, hello)
|
||||||
end
|
end
|
||||||
@@ -23,7 +23,7 @@ function hotfix(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
]]))
|
]]))
|
||||||
print(ps.pub.hello())
|
print(ps.post.hello())
|
||||||
print(snax.kill(ps,"exit"))
|
print(snax.kill(ps,"exit"))
|
||||||
skynet.exit()
|
skynet.exit()
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user