| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /**
- * @description job executor for animation.
- * @author <a href="mailto:lingosurf168@gmail.com">Lingo Surf168</a>
- *
- * @class
- * @param {Replay} replay replay
- */
- JobExecutor = function(replay) {
- this.replay = replay;
- this.running = false;
- };
- JobExecutor.prototype = {
- /**
- * @description start running.
- */
- start: function() {
- if (this.running !== true) {
- this.running = true;
- this.tid = new Date().getTime();
- this.run(this.tid);
- }
- },
- /**
- * @description running.
- * @param tid transactionId use to avoid the speed up when multi replays
- */
- run: function(tid) {
- if (this.running !== true) {
- return;
- }
- if (tid != this.tid) {
- return;
- }
- var count = 0;
- var tokens = Array.prototype.slice.call(this.replay.tokens, 0);
- for (var i = 0; i < tokens.length; i++) {
- var token = tokens[i];
- if (token.status === 'running') {
- count++;
- token.move();
- }
- }
- if (count !== 0) {
- var self = this;
- setTimeout(function() {
- self.run(tid);
- }, 100);
- } else {
- this.running = false;
- var tokens = [];
- for (var i = 0; i < this.replay.tokens.length; i++) {
- var token = this.replay.tokens[i];
- if (token.status !== 'removed') {
- tokens.push(token);
- }
- }
- this.replay.tokens = tokens;
- }
- }
- };
|