Refactor Queue.js.

This commit is contained in:
Christian Williams 2009-10-12 17:22:00 -05:00
parent d27684d280
commit e1ebc1e692
1 changed files with 26 additions and 35 deletions

View File

@ -20,49 +20,40 @@ jasmine.Queue.prototype.insertNext = function (block) {
}; };
jasmine.Queue.prototype.start = function(onComplete) { jasmine.Queue.prototype.start = function(onComplete) {
var self = this; this.running = true;
self.running = true; this.onComplete = onComplete;
self.onComplete = onComplete; this.next_();
if (self.blocks[0]) {
self.blocks[0].execute(function () {
self._next();
});
} else {
self.finish();
}
}; };
jasmine.Queue.prototype.isRunning = function () { jasmine.Queue.prototype.isRunning = function () {
return this.running; return this.running;
}; };
jasmine.Queue.prototype._next = function () { var nestLevel = 0;
jasmine.Queue.prototype.next_ = function () {
var self = this; var self = this;
var doNext = function () { if (self.index < self.blocks.length) {
self.offset = 0; self.blocks[self.index].execute(function () {
self.index++; var doNext = function () {
if (self.index < self.blocks.length) { self.offset = 0;
self.blocks[self.index].execute(function () { self.index++;
self._next(); self.next_();
}); };
} else {
self.finish(); var now = new Date().getTime();
} if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) {
}; self.env.lastUpdate = now;
var now = new Date().getTime(); self.env.setTimeout(doNext, 0);
if (this.env.updateInterval && now - this.env.lastUpdate > this.env.updateInterval) { } else {
this.env.lastUpdate = now; doNext();
this.env.setTimeout(doNext, 0); }
});
} else { } else {
doNext(); self.running = false;
} if (self.onComplete) {
self.onComplete();
}; }
jasmine.Queue.prototype.finish = function () {
this.running = false;
if (this.onComplete) {
this.onComplete();
} }
}; };