Skip to content

Commit

Permalink
Separate vicious.call into sync and async versions
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Sep 27, 2020
1 parent 82cffa8 commit 9df7237
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
-- Vicious module initialization
-- Copyright (C) 2009 Lucas de Vries <[email protected]>
-- Copyright (C) 2009-2013 Adrian C. (anrxc) <[email protected]>
-- Copyright (C) 2011 Joerg T. (Mic92) <[email protected]>
-- Copyright (C) 2011-2017 Joerg Thalheim <[email protected]>
-- Copyright (C) 2012 Arvydas Sidorenko <[email protected]>
-- Copyright (C) 2012 Jörg Thalheim <[email protected]>
-- Copyright (C) 2013 Dodo <[email protected]>
-- Copyright (C) 2013-2014,2017 Jörg Thalheim <[email protected]>
-- Copyright (C) 2014 blastmaster <[email protected]>
-- Copyright (C) 2015 Daniel Hahler <git@thequod.de>
-- Copyright (C) 2015,2019 Daniel Hahler <github@thequod.de>
-- Copyright (C) 2017 James Reed <[email protected]>
-- Copyright (C) 2017 Joerg Thalheim <[email protected]>
-- Copyright (C) 2017 getzze <[email protected]>
-- Copyright (C) 2017 mutlusun <[email protected]>
-- Copyright (C) 2018 Beniamin Kalinowski <[email protected]>
-- Copyright (C) 2018 Nguyễn Gia Phong <[email protected]>
-- Copyright (C) 2019 Daniel Hahler <[email protected]>
-- Copyright (C) 2018,2020 Nguyễn Gia Phong <[email protected]>
--
-- This file is part of Vicious.
--
Expand Down Expand Up @@ -322,16 +318,39 @@ function vicious.activate(widget)
end
-- }}}

-- {{{ Get custom widget format data
function vicious.call(myw, format, warg)
local mydata = myw(format, warg)
-- {{{ Get formatted data from a synchronous widget type
function vicious.call(wtype, format, warg)
if wtype.async ~= nil then return nil end

local data = wtype(format, warg)
if type(format) == "string" then
return helpers.format(format, mydata)
return helpers.format(format, data)
elseif type(format) == "function" then
return format(myw, mydata)
return format(wtype, data)
end
end
-- }}}

-- {{{ Get formatted data from an asynchronous widget type
function vicious.call_async(wtype, format, warg, callback)
if wtype.async == nil then
callback()
return
end

wtype.async(
format, warg,
function (data)
if type(format) == "string" then
callback(helpers.format(format, data))
elseif type(format) == "function" then
callback(format(wtype, data))
else
callback()
end
end)
end
-- }}}

return vicious
-- }}}

0 comments on commit 9df7237

Please sign in to comment.