| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class _Timer implements Timer { | 5 class _Timer implements Timer { |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * Set jitter to wake up timer events that would happen in _TIMER_JITTER ms. | 8 * Set jitter to wake up timer events that would happen in _TIMER_JITTER ms. |
| 9 */ | 9 */ |
| 10 static final int _TIMER_JITTER = 0; | 10 static final int _TIMER_JITTER = 0; |
| 11 | 11 |
| 12 /* | 12 /* |
| 13 * Disables the timer. | 13 * Disables the timer. |
| 14 */ | 14 */ |
| 15 static final int _NO_TIMER = -1; | 15 static final int _NO_TIMER = -1; |
| 16 | 16 |
| 17 factory _Timer(void callback(Timer timer), | 17 static Timer _createTimer(void callback(Timer timer), |
| 18 int milliSeconds, | 18 int milliSeconds, |
| 19 bool repeating) { | 19 bool repeating) { |
| 20 EventHandler._start(); | 20 EventHandler._start(); |
| 21 if (_timers === null) { | 21 if (_timers === null) { |
| 22 _timers = new DoubleLinkedQueue<_Timer>(); | 22 _timers = new DoubleLinkedQueue<_Timer>(); |
| 23 } | 23 } |
| 24 Timer timer = new _Timer._internal(); | 24 Timer timer = new _Timer._internal(); |
| 25 timer._callback = callback; | 25 timer._callback = callback; |
| 26 timer._milliSeconds = milliSeconds; | 26 timer._milliSeconds = milliSeconds; |
| 27 timer._wakeupTime = (new Date.now()).value + milliSeconds; | 27 timer._wakeupTime = (new Date.now()).value + milliSeconds; |
| 28 timer._repeating = repeating; | 28 timer._repeating = repeating; |
| 29 timer._addTimerToList(); | 29 timer._addTimerToList(); |
| 30 timer._notifyEventHandler(); | 30 timer._notifyEventHandler(); |
| 31 return timer; | 31 return timer; |
| 32 } | 32 } |
| 33 | 33 |
| 34 factory _Timer(void callback(Timer timer), int milliSeconds) { |
| 35 return _createTimer(callback, milliSeconds, false); |
| 36 } |
| 37 |
| 38 factory _Timer.repeating(void callback(Timer timer), int milliSeconds) { |
| 39 return _createTimer(callback, milliSeconds, true); |
| 40 } |
| 41 |
| 34 _Timer._internal() {} | 42 _Timer._internal() {} |
| 35 | 43 |
| 36 void _clear() { | 44 void _clear() { |
| 37 _callback = null; | 45 _callback = null; |
| 38 _milliSeconds = 0; | 46 _milliSeconds = 0; |
| 39 _wakeupTime = 0; | 47 _wakeupTime = 0; |
| 40 _repeating = false; | 48 _repeating = false; |
| 41 } | 49 } |
| 42 | 50 |
| 43 /* | 51 /* |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 185 |
| 178 static ReceivePort _receivePort; | 186 static ReceivePort _receivePort; |
| 179 static bool _handling_callbacks = false; | 187 static bool _handling_callbacks = false; |
| 180 | 188 |
| 181 var _callback; | 189 var _callback; |
| 182 int _milliSeconds; | 190 int _milliSeconds; |
| 183 int _wakeupTime; | 191 int _wakeupTime; |
| 184 bool _repeating; | 192 bool _repeating; |
| 185 } | 193 } |
| 186 | 194 |
| OLD | NEW |