util.watchdog

util.watchdog implements a watchdog timer. It calls a callback function after a set time if the :reset() method is not called regularly.

API

local watchdog = require "prosody.util.watchdog";

new(timeout, callback)

Create a new watchdog. Arguments are a timeout and a callback function.

local watcher = watchdog.new(60, function()
    print("Timeout reached")
end)

The callback is called some time after 60 seconds has passed if the :reset() method has not been called before then.

:reset(new_timeout)

Reset the timer, delaying the callback for another timeout seconds, or new_timeout seconds if provided.

watcher:reset()

:cancel()

Stop the timer completely, preventing the callback from being called. The timer can be restarted by calling :reset().

watcher:cancel()