change name from pub/subscribe to post/accept

This commit is contained in:
Cloud Wu
2014-04-22 11:40:08 +08:00
parent 56fdbef851
commit 08c511160f
5 changed files with 12 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ function snax.interface(name)
local si = snax_interface(name, G)
local ret = {
subscribe = {},
accept = {},
response = {},
system = {},
}
@@ -33,10 +33,10 @@ local meta = { __tostring = function(v) return string.format("[%s:%x]", v.type,
local skynet_send = skynet.send
local skynet_call = skynet.call
local function gen_pub(type, handle)
local function gen_post(type, handle)
return setmetatable({} , {
__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(...)
skynet_send(handle, "lua", id, ...)
end
@@ -55,7 +55,7 @@ end
local function wrapper(handle, name, type)
return setmetatable ({
pub = gen_pub(type, handle),
post = gen_post(type, handle),
req = gen_req(type, handle),
type = name,
handle = handle,

View File

@@ -27,7 +27,7 @@ return function (name , G, loader)
assert(G.init == nil)
assert(G.exit == nil)
assert(G.subscribe == nil)
assert(G.accept == nil)
assert(G.response == nil)
end
@@ -44,7 +44,7 @@ return function (name , G, loader)
end
end
env.subscribe = func_id(func, "subscribe")
env.accept = func_id(func, "accept")
env.response = func_id(func, "response")
local function init_system(t, name, f)

View File

@@ -26,7 +26,7 @@ local function message_dispatch()
local method = msg.method
local f = method[4]
if f then
if method[2] == "subscribe" then
if method[2] == "accept" then
-- no return
local ok, data = pcall(f, table.unpack(msg))
if not ok then
@@ -94,7 +94,7 @@ skynet.start(function()
assert(init, "Init first")
if mode == "queue" then
queue(session, source, method , ...)
elseif method[2] == "subscribe" then
elseif method[2] == "accept" then
-- no return
method[4](...)
else

View File

@@ -8,7 +8,7 @@ function response.ping(hello)
return hello
end
function subscribe.hello()
function accept.hello()
i = i + 1
print (i, hello)
end

View File

@@ -4,14 +4,14 @@ local snax = require "snax"
skynet.start(function()
local ps = snax.newservice ("pingserver", "hello world")
print(ps.req.ping("foobar"))
print(ps.pub.hello())
print(ps.post.hello())
print(pcall(ps.req.error))
print("Hotfix (i) :", snax.hotfix(ps, [[
local i
local hello
function subscribe.hello()
function accept.hello()
i = i + 1
print ("fix", i, hello)
end
@@ -23,7 +23,7 @@ function hotfix(...)
end
]]))
print(ps.pub.hello())
print(ps.post.hello())
print(snax.kill(ps,"exit"))
skynet.exit()
end)