Skip to content

Commit

Permalink
check callback
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Nov 29, 2024
1 parent ec5d9b9 commit c098d6f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
8 changes: 6 additions & 2 deletions kong/clustering/rpc/concentrator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,13 @@ end
-- This way the manager code wouldn't tell the difference
-- between calls made over WebSocket or concentrator
function _M:call(node_id, method, params, callback)
local id = self:_get_next_id()
local id

self.interest[id] = callback
-- notification has no callback or id
if callback then
id = self:_get_next_id()
self.interest[id] = callback
end

return self:_enqueue_rpc_request(node_id, {
jsonrpc = "2.0",
Expand Down
12 changes: 11 additions & 1 deletion kong/clustering/rpc/future.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local STATE_SUCCEED = 3
local STATE_ERRORED = 4


function _M.new(node_id, socket, method, params)
function _M.new(node_id, socket, method, params, is_notification)
local self = {
method = method,
params = params,
Expand All @@ -22,6 +22,7 @@ function _M.new(node_id, socket, method, params)
result = nil,
error = nil,
state = STATE_NEW, -- STATE_*
is_notification = is_notification,
}

return setmetatable(self, _MT)
Expand All @@ -33,6 +34,15 @@ function _M:start()
assert(self.state == STATE_NEW)
self.state = STATE_IN_PROGRESS

-- notification has no callback
if self.is_notification then
self.sema:post()

return self.socket:call(self.node_id,
self.method,
self.params)
end

local callback = function(resp)
assert(resp.jsonrpc == "2.0")

Expand Down
20 changes: 6 additions & 14 deletions kong/clustering/rpc/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,13 @@ end
function _M:call(node_id, method, params, callback)
assert(node_id == self.node_id)

local id = self:_get_next_id()
local id

self.interest[id] = callback
-- notification has no callback or id
if callback then
id = self:_get_next_id()
self.interest[id] = callback
end

return self.outgoing:push({
jsonrpc = "2.0",
Expand All @@ -289,16 +293,4 @@ function _M:call(node_id, method, params, callback)
end


function _M:notify(node_id, method, params)
assert(node_id == self.node_id)

return self.outgoing:push({
jsonrpc = "2.0",
method = method,
params = params,
-- notification has no id
})
end


return _M

0 comments on commit c098d6f

Please sign in to comment.