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