jasmine.Queue = function(env) { this.env = env; // parallel to blocks. each true value in this array means the block will // get executed even if we abort this.ensured = []; this.blocks = []; this.running = false; this.index = 0; this.offset = 0; this.abort = false; }; jasmine.Queue.prototype.addBefore = function(block, ensure) { if (ensure === this.env.undefined) { ensure = false; } this.blocks.unshift(block); this.ensured.unshift(ensure); }; jasmine.Queue.prototype.add = function(block, ensure) { if (ensure === this.env.undefined) { ensure = false; } this.blocks.push(block); this.ensured.push(ensure); }; jasmine.Queue.prototype.insertNext = function(block, ensure) { if (ensure === this.env.undefined) { ensure = false; } this.ensured.splice((this.index + this.offset + 1), 0, ensure); this.blocks.splice((this.index + this.offset + 1), 0, block); this.offset++; }; jasmine.Queue.prototype.start = function(onComplete) { this.running = true; this.onComplete = onComplete; this.next_(); }; jasmine.Queue.prototype.isRunning = function() { return this.running; }; jasmine.Queue.LOOP_DONT_RECURSE = true; jasmine.Queue.prototype.incrementQueue = function() { if (this.blocks[this.index].abort) { this.abort = true; } this.offset = 0; this.index++; this.next_(); } jasmine.Queue.prototype.next_ = function() { var self = this; // var goAgain = true; // while (goAgain) { // goAgain = false; if (self.index < self.blocks.length && !(this.abort && !this.ensured[self.index])) { // var calledSynchronously = true; // var completedSynchronously = false; // var onComplete = function () { // if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { // completedSynchronously = true; // return; // } self.blocks[self.index].execute(function() { self.incrementQueue() }); // var now = new Date().getTime(); // if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { // self.env.lastUpdate = now; // self.env.setTimeout(function() { // self.next_(); // }, 0); // } else { // if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { // goAgain = true; // } else { // self.next_(); // } // } // }; // self.blocks[self.index].execute(function() { self.next_(); }); // calledSynchronously = false; // if (completedSynchronously) { // onComplete(); // } } else { self.running = false; if (self.onComplete) { self.onComplete(); } } // } };