1
1
Fork 0
mirror of https://github.com/vicious-widgets/vicious synced 2023-12-14 07:13:07 +01:00

Let existing async wtype use helpers.setasyncall

This commit is contained in:
Nguyễn Gia Phong 2019-05-15 16:05:16 +07:00
parent 6ba97712f5
commit 92a2138296
3 changed files with 4 additions and 32 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)