Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/moment-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -26,7 +27,7 @@
var self = this;
setTimeout(function () {
if (attributes.executeAfterWait) {
callback();
callback(self.args);
}
self.start();
}, attributes.wait);
Expand All @@ -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());

Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down