| 50 | } |
| 51 | |
| 52 | public start():void { |
| 53 | if (this._timer < 0) { |
| 54 | this._lastToken = Date.now(); |
| 55 | var _self:TimerRuntime = this; |
| 56 | this._timer = setInterval( () => { |
| 57 | var elapsed:number = Date.now() - _self._lastToken; |
| 58 | for (var i = 0; i < _self._timers.length; i++) { |
| 59 | var timer:RuntimeTimer = _self._timers[i]; |
| 60 | if (timer.type === "timeout") { |
| 61 | timer.ttl -= elapsed; |
| 62 | if (timer.ttl <= 0) { |
| 63 | try { |
| 64 | timer.callback(); |
| 65 | }catch(e){ |
| 66 | __trace(e.stack.toString(), 'err'); |
| 67 | } |
| 68 | _self._timers.splice(i, 1); |
| 69 | i--; |
| 70 | } |
| 71 | } else if (timer.type === 'interval') { |
| 72 | timer.ttl -= elapsed; |
| 73 | if (timer.ttl <= 0) { |
| 74 | try { |
| 75 | timer.callback(); |
| 76 | }catch(e){ |
| 77 | __trace(e.stack.toString(), 'err'); |
| 78 | } |
| 79 | timer.ttl += timer.dur; |
| 80 | } |
| 81 | }else{ |
| 82 | // Do nothing |
| 83 | } |
| 84 | } |
| 85 | _self._lastToken = Date.now(); |
| 86 | }, this._precision); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | public stop():void { |
| 91 | if (this._timer > -1) { |