Software /
code /
prosody
File
util/watchdog.lua @ 12945:d2c1c327a4d1
util.sasl.{scram,plain}: Pass authzid to SASL profile callback
For potential future use.
Used for logging into a different account than the one used for
authentication.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 16 Mar 2023 13:57:30 +0100 |
parent | 12547:e79c64b2dfed |
child | 12975:d10957394a3c |
line wrap: on
line source
local timer = require "util.timer"; local setmetatable = setmetatable; local _ENV = nil; -- luacheck: std none local watchdog_methods = {}; local watchdog_mt = { __index = watchdog_methods }; local function new(timeout, callback) local watchdog = setmetatable({ timeout = timeout; callback = callback; timer_id = nil; }, watchdog_mt); watchdog:reset(); -- Kick things off return watchdog; end function watchdog_methods:reset(new_timeout) if new_timeout then self.timeout = new_timeout; end if self.timer_id then timer.reschedule(self.timer_id, self.timeout+1); else self.timer_id = timer.add_task(self.timeout+1, function () return self:callback(); end); end end function watchdog_methods:cancel() if self.timer_id then timer.stop(self.timer_id); self.timer_id = nil; end end return { new = new; };