A
local channels= {}Как можно организовать подписку на несколько ключей в одном соединении? Использовать несколько каналов? Вместо ключа сохранять session_id, key и уведомлять session_id вместо key?
local api_listen = function (req)
local space = req:stash('space')
local key = req:stash('key')
if not box.space[space]:get(key) then return { status = 404, body = empty_json } end
local timeout = 25
local channel_id = space .. key
local wait = channels[channel_id]
if not wait then
wait = fiber.channel()
channels[channel_id] = wait
end
local new_updates = wait:get(timeout)
if new_updates.sid and new_updates.sid ~= box.session.id() then
return { status = 200, body = json.encode(new_updates.t['val']), headers = headers }
end
if not new_updates then return { status = 204, body = empty_json } end
end