Blame view

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