cleanup / array rx support
This commit is contained in:
parent
eea0736296
commit
93690fdf6e
@ -1,8 +1,6 @@
|
||||
-- bi-directional http-channel
|
||||
-- with long-poll GET and POST on the same URL
|
||||
|
||||
local debug = false
|
||||
|
||||
local function Channel(http, url, cfg)
|
||||
cfg = cfg or {}
|
||||
local extra_headers = cfg.extra_headers or {}
|
||||
@ -33,15 +31,19 @@ local function Channel(http, url, cfg)
|
||||
if res.succeeded and res.code == 200 then
|
||||
local data = minetest.parse_json(res.data)
|
||||
|
||||
if debug then
|
||||
minetest.log("action", "[webmail-rx] " .. dump(data))
|
||||
end
|
||||
|
||||
if data then
|
||||
for _,listener in pairs(recv_listeners) do
|
||||
if #data > 0 then
|
||||
-- array received
|
||||
for _, entry in ipairs(data) do
|
||||
listener(entry)
|
||||
end
|
||||
else
|
||||
-- single item received
|
||||
listener(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- reschedule immediately
|
||||
minetest.after(0, recv_loop)
|
||||
else
|
||||
@ -56,10 +58,6 @@ local function Channel(http, url, cfg)
|
||||
assert(run)
|
||||
-- POST
|
||||
|
||||
if debug then
|
||||
minetest.log("action", "[webmail-tx] " .. dump(data))
|
||||
end
|
||||
|
||||
http.fetch({
|
||||
url = url,
|
||||
extra_headers = post_headers,
|
||||
|
Loading…
Reference in New Issue
Block a user