Add configurable interval

This commit is contained in:
s1341 2013-12-08 20:22:14 +02:00
parent 30279e2fe3
commit 47a6c74bde

View file

@ -177,10 +177,11 @@ $.Class("Thread",
{//statics {//statics
}, },
{//instance {//instance
init: function () { init: function (interval) {
this.is_running = false; this._is_running = false;
this.is_stopping = false; this._is_stopping = false;
this._interval_id = null; this._interval_id = null;
this._interval = interval ? interval : 1000;
}, },
_run: function () { _run: function () {
console.log("[thread] tick"); console.log("[thread] tick");
@ -190,20 +191,20 @@ $.Class("Thread",
var _this = this; var _this = this;
console.log("[thread] starting") console.log("[thread] starting")
var wrapper = function () { var wrapper = function () {
if (_this.is_running && _this.is_stopping) { if (_this._is_running && _this._is_stopping) {
console.log("[thread] shutting down") console.log("[thread] shutting down")
clearInterval(_this._interval_id); clearInterval(_this._interval_id);
_this.is_running = false; _this._is_running = false;
return; return;
} }
_this._run.apply(_this); _this._run.apply(_this);
}; };
this._interval_id = setInterval(wrapper, 1000); this._interval_id = setInterval(wrapper, this._interval);
this.is_running = true; this._is_running = true;
}, },
// stop the run loop // stop the run loop
stop: function () { stop: function () {
this.is_stopping = true; this._is_stopping = true;
console.log("[thread] request stop") console.log("[thread] request stop")
// TODO: consider finding a way to make this block // TODO: consider finding a way to make this block
// or alternatively, having a callback which is called // or alternatively, having a callback which is called
@ -228,7 +229,7 @@ Thread("ChangesetLoader",
}, },
{//instance {//instance
init: function () { init: function () {
this._super(); this._super(100);
this.queue_large = []; this.queue_large = [];
this.queue_medium = []; this.queue_medium = [];
this.queue_small = []; this.queue_small = [];