diff --git a/contrib/btc_all.lua b/contrib/btc_all.lua index b107a47..e28cada 100644 --- a/contrib/btc_all.lua +++ b/contrib/btc_all.lua @@ -4,7 +4,6 @@ --------------------------------------------------- -- {{{ Grab environment -local setmetatable = setmetatable local pcall = pcall local helpers = require("vicious.helpers") local spawn = require("vicious.spawn") @@ -51,13 +50,6 @@ function btc_all.async(format, warg, callback) spawn.easy_async(cmd, function(stdout) callback(parse(stdout)) end) end - -local function worker(format, warg) - local ret - btc_all.async(format, warg, function (price) ret = price end) - while ret == nil do end - return ret -end -- }}} -return setmetatable(btc_all, { __call = function(_, ...) return worker(...) end }) +return helpers.setasyncall(btc_all) diff --git a/widgets/pkg_all.lua b/widgets/pkg_all.lua index bbefc63..639ba4e 100644 --- a/widgets/pkg_all.lua +++ b/widgets/pkg_all.lua @@ -4,8 +4,8 @@ --------------------------------------------------- -- {{{ Grab environment -local setmetatable = setmetatable local spawn = require("vicious.spawn") +local helpers = require("vicious.helpers") -- }}} @@ -42,16 +42,4 @@ function pkg_all.async(format, warg, callback) end -- }}} --- {{{ Packages widget type -local function worker(format, warg) - local ret = nil - - pkg_all.async(format, warg, function(data) ret = data end) - - while ret==nil do end - return ret -end --- }}} - - -return setmetatable(pkg_all, { __call = function(_, ...) return worker(...) end }) +return helpers.setasyncall(pkg_all) diff --git a/widgets/weather_all.lua b/widgets/weather_all.lua index f38ec8b..6bd4cfc 100644 --- a/widgets/weather_all.lua +++ b/widgets/weather_all.lua @@ -5,7 +5,6 @@ -- {{{ Grab environment local tonumber = tonumber -local setmetatable = setmetatable local math = { ceil = math.ceil } local string = { match = string.match } @@ -91,13 +90,6 @@ function weather_all.async(format, warg, callback) spawn.easy_async("curl -fs " .. url, function (...) callback(parse(...)) end) end - -local function worker(format, warg) - local ret - weather_all.async(format, warg, function (weather) ret = weather end) - while ret == nil do end - return ret -end -- }}} -return setmetatable(weather_all, { __call = function(_, ...) return worker(...) end }) +return helpers.setasyncall(weather_all)