From 7bc92b3bfcfebefcbbb96f0951edf69c26d49c3d Mon Sep 17 00:00:00 2001 From: lareck70 <108877259+lareck70@users.noreply.github.com> Date: Tue, 12 Jul 2022 13:14:08 +0200 Subject: [PATCH] add parameter / add execute - add parameter to callback - add function to call callback directly --- lib/moment-timer.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/moment-timer.js b/lib/moment-timer.js index 01fbe48..0e19145 100644 --- a/lib/moment-timer.js +++ b/lib/moment-timer.js @@ -14,6 +14,7 @@ function Timer(duration, attributes, callback) { this.timerDuration = duration; this.callback = callback; + this.args = attributes.args; this.loop = attributes.loop; this.started = false; this.stopped = false; // If stop() is called this variable will be used to finish the paused duration once it's started again. @@ -26,7 +27,7 @@ var self = this; setTimeout(function () { if (attributes.executeAfterWait) { - callback(); + callback(self.args); } self.start(); }, attributes.wait); @@ -44,7 +45,7 @@ // Takes care of restarts. If the timer has been stopped, this will make sure the leftover duration is executed. if (this.stopped) { setTimeout(function () { - self.callback(); + self.callback(self.args); return self.start(); }, this.getRemainingDuration()); @@ -63,6 +64,12 @@ return false; } + Timer.prototype.execute = function () { + var self = this; + + self.callback(self.args); + } + Timer.prototype.stop = function () { if (this.started) { this.clearTimer(); @@ -131,12 +138,12 @@ if (this.loop) { this.timer = setInterval(function () { self.updateStartEndTickFromDuration(self.timerDuration); - return self.callback(); + return self.callback(self.args); }, this.timerDuration); } else { this.timer = setTimeout(function () { self.started = false; - return self.callback(); + return self.callback(self.args); }, this.timerDuration); } }