# HG changeset patch # User Matthew Wild # Date 1335191920 -3600 # Node ID fb522fbd495ef07599b98aae51186519e4a76ae4 # Parent 6be91ca54613401a48bcec12ef68441b748fb6d3 moduleapi: Add module:add_timer(delay, callback) - automatically halts the timer on module unload diff -r 6be91ca54613 -r fb522fbd495e core/moduleapi.lua --- a/core/moduleapi.lua Mon Apr 23 15:38:36 2012 +0100 +++ b/core/moduleapi.lua Mon Apr 23 15:38:40 2012 +0100 @@ -316,4 +316,11 @@ return core_post_stanza(hosts[self.host], stanza); end +function api:add_timer(delay, callback) + return timer.add_task(delay, function (t) + if self.loaded == false then return; end + return callback(t); + end); +end + return api;