1 jasmine.Queue = function(env) { 2 this.env = env; 3 this.blocks = []; 4 this.running = false; 5 this.index = 0; 6 this.offset = 0; 7 }; 8 9 jasmine.Queue.prototype.addBefore = function(block) { 10 this.blocks.unshift(block); 11 }; 12 13 jasmine.Queue.prototype.add = function(block) { 14 this.blocks.push(block); 15 }; 16 17 jasmine.Queue.prototype.insertNext = function(block) { 18 this.blocks.splice((this.index + this.offset + 1), 0, block); 19 this.offset++; 20 }; 21 22 jasmine.Queue.prototype.start = function(onComplete) { 23 this.running = true; 24 this.onComplete = onComplete; 25 this.next_(); 26 }; 27 28 jasmine.Queue.prototype.isRunning = function() { 29 return this.running; 30 }; 31 32 jasmine.Queue.LOOP_DONT_RECURSE = true; 33 34 jasmine.Queue.prototype.next_ = function() { 35 var self = this; 36 var goAgain = true; 37 38 while (goAgain) { 39 goAgain = false; 40 41 if (self.index < self.blocks.length) { 42 var calledSynchronously = true; 43 var completedSynchronously = false; 44 45 var onComplete = function () { 46 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { 47 completedSynchronously = true; 48 return; 49 } 50 51 self.offset = 0; 52 self.index++; 53 54 var now = new Date().getTime(); 55 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { 56 self.env.lastUpdate = now; 57 self.env.setTimeout(function() { 58 self.next_(); 59 }, 0); 60 } else { 61 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { 62 goAgain = true; 63 } else { 64 self.next_(); 65 } 66 } 67 }; 68 self.blocks[self.index].execute(onComplete); 69 70 calledSynchronously = false; 71 if (completedSynchronously) { 72 onComplete(); 73 } 74 75 } else { 76 self.running = false; 77 if (self.onComplete) { 78 self.onComplete(); 79 } 80 } 81 } 82 }; 83 84 jasmine.Queue.prototype.results = function() { 85 var results = new jasmine.NestedResults(); 86 for (var i = 0; i < this.blocks.length; i++) { 87 if (this.blocks[i].results) { 88 results.addResult(this.blocks[i].results()); 89 } 90 } 91 return results; 92 }; 93 94 95