degesch: replace degesch.connect with async.dial

Halfway there, looks much saner.
This commit is contained in:
2016-11-04 21:50:46 +01:00
parent 52d1ded7df
commit e2bb051bd3
2 changed files with 139 additions and 155 deletions

View File

@@ -118,24 +118,23 @@ end
local running
-- Initiate a connection to last.fm servers
async, await = degesch.async, coroutine.yield
local make_request = function (buffer, action)
if not user or not api_key then
report_error (buffer, "configuration is incomplete")
return
end
if running then running.abort () end
running = degesch.connect ("ws.audioscrobbler.com", 80, {
on_success = function (c, host)
on_connected (buffer, c, host, action)
running = nil
end,
on_error = function (e)
if running then running:cancel () end
running = async.go (function ()
local c, host, e = await (async.dial ("ws.audioscrobbler.com", 80))
if e then
report_error (buffer, e)
running = nil
else
on_connected (buffer, c, host, action)
end
})
running = nil
end)
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -