aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-11-04 21:50:46 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-11-04 22:02:26 +0100
commite2bb051bd352bfae50f0ddcbcef844e62fa146fc (patch)
treeeef053e607947e24b13d975a61e138a139df773b /plugins
parent52d1ded7dfde6adf77047c4b9a50e323d3fc86dd (diff)
downloadxK-e2bb051bd352bfae50f0ddcbcef844e62fa146fc.tar.gz
xK-e2bb051bd352bfae50f0ddcbcef844e62fa146fc.tar.xz
xK-e2bb051bd352bfae50f0ddcbcef844e62fa146fc.zip
degesch: replace degesch.connect with async.dial
Halfway there, looks much saner.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/degesch/last-fm.lua19
1 files changed, 9 insertions, 10 deletions
diff --git a/plugins/degesch/last-fm.lua b/plugins/degesch/last-fm.lua
index 5c836ca..8f6902d 100644
--- a/plugins/degesch/last-fm.lua
+++ b/plugins/degesch/last-fm.lua
@@ -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
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -