Skip to content

Commit 9df7237

Browse files
committed
Separate vicious.call into sync and async versions
1 parent 82cffa8 commit 9df7237

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

init.lua

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
-- Vicious module initialization
22
-- Copyright (C) 2009 Lucas de Vries <[email protected]>
33
-- Copyright (C) 2009-2013 Adrian C. (anrxc) <[email protected]>
4-
-- Copyright (C) 2011 Joerg T. (Mic92) <[email protected]>
4+
-- Copyright (C) 2011-2017 Joerg Thalheim <[email protected]>
55
-- Copyright (C) 2012 Arvydas Sidorenko <[email protected]>
6-
-- Copyright (C) 2012 Jörg Thalheim <[email protected]>
76
-- Copyright (C) 2013 Dodo <[email protected]>
8-
-- Copyright (C) 2013-2014,2017 Jörg Thalheim <[email protected]>
97
-- Copyright (C) 2014 blastmaster <[email protected]>
10-
-- Copyright (C) 2015 Daniel Hahler <git@thequod.de>
8+
-- Copyright (C) 2015,2019 Daniel Hahler <github@thequod.de>
119
-- Copyright (C) 2017 James Reed <[email protected]>
12-
-- Copyright (C) 2017 Joerg Thalheim <[email protected]>
1310
-- Copyright (C) 2017 getzze <[email protected]>
1411
-- Copyright (C) 2017 mutlusun <[email protected]>
1512
-- Copyright (C) 2018 Beniamin Kalinowski <[email protected]>
16-
-- Copyright (C) 2018 Nguyễn Gia Phong <[email protected]>
17-
-- Copyright (C) 2019 Daniel Hahler <[email protected]>
13+
-- Copyright (C) 2018,2020 Nguyễn Gia Phong <[email protected]>
1814
--
1915
-- This file is part of Vicious.
2016
--
@@ -322,16 +318,39 @@ function vicious.activate(widget)
322318
end
323319
-- }}}
324320

325-
-- {{{ Get custom widget format data
326-
function vicious.call(myw, format, warg)
327-
local mydata = myw(format, warg)
321+
-- {{{ Get formatted data from a synchronous widget type
322+
function vicious.call(wtype, format, warg)
323+
if wtype.async ~= nil then return nil end
324+
325+
local data = wtype(format, warg)
328326
if type(format) == "string" then
329-
return helpers.format(format, mydata)
327+
return helpers.format(format, data)
330328
elseif type(format) == "function" then
331-
return format(myw, mydata)
329+
return format(wtype, data)
332330
end
333331
end
334332
-- }}}
335333

334+
-- {{{ Get formatted data from an asynchronous widget type
335+
function vicious.call_async(wtype, format, warg, callback)
336+
if wtype.async == nil then
337+
callback()
338+
return
339+
end
340+
341+
wtype.async(
342+
format, warg,
343+
function (data)
344+
if type(format) == "string" then
345+
callback(helpers.format(format, data))
346+
elseif type(format) == "function" then
347+
callback(format(wtype, data))
348+
else
349+
callback()
350+
end
351+
end)
352+
end
353+
-- }}}
354+
336355
return vicious
337356
-- }}}

0 commit comments

Comments
 (0)