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