Skip to content

Commit

Permalink
fix: Swapped interval for timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonmoeller committed Oct 13, 2016
1 parent ccbe1c3 commit ab666d6
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/clock.js
Expand Up @@ -15,27 +15,29 @@ function Clock(jobs) {
this.jobs = jobs;

/**
* @property {Number} intervalId
* @property {Number} timeoutId
*/
this.intervalId = null;
this.timeoutId = null;

/**
* @property {Number} resolution
*/
this.resolution = 100;

this.tick = this.tick.bind(this);
}

/**
* @method start
* @return {this}
*/
Clock.prototype.start = function start() {
if (this.intervalId) {
if (this.timeoutId) {
return this;
}

this.intervalId = setInterval(
this.tick.bind(this),
this.timeoutId = setTimeout(
this.tick,
this.resolution
);

Expand All @@ -47,12 +49,12 @@ Clock.prototype.start = function start() {
* @return {this}
*/
Clock.prototype.stop = function stop() {
if (!this.intervalId) {
if (!this.timeoutId) {
return this;
}

this.intervalId = clearInterval(
this.intervalId
this.timeoutId = clearTimeout(
this.timeoutId
);

return this;
Expand Down Expand Up @@ -87,6 +89,11 @@ Clock.prototype.tick = function tick() {

this.jobs.forEach(tickJob);

this.timeoutId = setTimeout(
this.tick,
this.resolution
);

return this;
};

Expand Down

0 comments on commit ab666d6

Please sign in to comment.