timer: Add a `singleshot` constructor property.

Also save some boilerplate code.

This closes the gap between timer.start_new and timer.new. Now the
only difference is that one have a special callback format while
the other only has predefined properties.
This commit is contained in:
Emmanuel Lepage Vallee 2016-12-28 23:57:38 -05:00
parent d8f51a4039
commit 595ade2228
1 changed files with 5 additions and 0 deletions

View File

@ -107,6 +107,7 @@ local timer_instance_mt = {
-- @tparam[opt=false] boolean args.autostart Automatically start the timer.
-- @tparam[opt=nil] function args.callback Callback function to connect to the
-- "timeout" signal.
-- @tparam[opt=false] boolean args.single_shot Run only once then stop.
-- @treturn timer
-- @function gears.timer
function timer.new(args)
@ -128,6 +129,10 @@ function timer.new(args)
ret:connect_signal("timeout", args.callback)
end
if args.single_shot then
ret:connect_signal("timeout", function() ret:stop() end)
end
return ret
end