From 8a7333cef3088272b07616d2367531e75c1c592a Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 9 Jun 2013 15:25:06 +0000 Subject: [PATCH] addTimeout for timers module [#494] --- modules/timers/timers.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/timers/timers.js b/modules/timers/timers.js index b1e968d..2acb505 100644 --- a/modules/timers/timers.js +++ b/modules/timers/timers.js @@ -34,6 +34,18 @@ var timers = function(dbot) { } }.bind(this), timeout)); } + }, + + 'addTimeout': function(date, callback, params) { + var now = new Date().getTime() + timeout = date.getTime() - now; + this.runningTimeouts.push(setTimeout(function() { + try { + callback.apply(callback, params); + } catch(err) { + console.log('Callback failed: ' + err); + } + }, timeout)); } };