local M = {}
function M.new()
local instance = {}
instance.handle = 0
instance.countdown = 0
instance.current_countdown = 0
function instance.start(_countdown)
instance.countdown = _countdown
instance.current_countdown = _countdown
if instance.handle then
timer.cancel(instance.handle)
end
instance.handle = timer.delay(1, true, function()
instance.current_countdown = instance.current_countdown - 1
if instance.current_countdown <= 0 then
timer.cancel(instance.handle)
end
end)
end
function instance.stop()
if instance.handle then
timer.cancel(instance.handle)
end
end
function instance.get_countdown()
return instance.current_countdown
end
return instance
end
return M