Skip to content

Commit

Permalink
task-loop: pre-bind tick method
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed Apr 5, 2018
1 parent faa4a93 commit 9f71225
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/task-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class TaskLoop extends EventHandler {
this._tickInterval = null;
this._tickTimer = null;
this._tickCallCount = 0;
this._boundTick = this.tick.bind(this);
}

/**
Expand Down Expand Up @@ -51,7 +52,7 @@ export default class TaskLoop extends EventHandler {
*/
setInterval (millis) {
if (!this._tickInterval) {
this._tickInterval = setInterval(this.tick.bind(this, false), millis);
this._tickInterval = setInterval(this._boundTick, millis);
return true;
}
return false;
Expand Down Expand Up @@ -94,7 +95,7 @@ export default class TaskLoop extends EventHandler {
if (this._tickCallCount > 1) {
// make sure only one timer exists at any time at max
this.clearNextTick();
this._tickTimer = setTimeout(this.tick.bind(this), 0);
this._tickTimer = setTimeout(this._boundTick, 0);
}

this._tickCallCount = 0;
Expand Down

0 comments on commit 9f71225

Please sign in to comment.