OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 class _Timer implements Timer { | 7 class _Timer implements Timer { |
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 static const int _TIMER_JITTER = 0; | 9 static const int _TIMER_JITTER = 0; |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 if (_callback != null) { | 77 if (_callback != null) { |
78 | 78 |
79 DoubleLinkedQueueEntry<_Timer> entry = _timers.firstEntry(); | 79 DoubleLinkedQueueEntry<_Timer> entry = _timers.firstEntry(); |
80 while (entry != null) { | 80 while (entry != null) { |
81 if (_wakeupTime < entry.element._wakeupTime) { | 81 if (_wakeupTime < entry.element._wakeupTime) { |
82 entry.prepend(this); | 82 entry.prepend(this); |
83 return; | 83 return; |
84 } | 84 } |
85 entry = entry.nextEntry(); | 85 entry = entry.nextEntry(); |
86 } | 86 } |
87 _timers.addLast(this); | 87 _timers.add(this); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 void _notifyEventHandler() { | 92 void _notifyEventHandler() { |
93 if (_handling_callbacks) { | 93 if (_handling_callbacks) { |
94 // While we are already handling callbacks we will not notify the event | 94 // While we are already handling callbacks we will not notify the event |
95 // handler. _handleTimeout will call _notifyEventHandler once all pending | 95 // handler. _handleTimeout will call _notifyEventHandler once all pending |
96 // timers are processed. | 96 // timers are processed. |
97 return; | 97 return; |
(...skipping 27 matching lines...) Expand all Loading... |
125 int currentTime = | 125 int currentTime = |
126 (new DateTime.now()).millisecondsSinceEpoch + _TIMER_JITTER; | 126 (new DateTime.now()).millisecondsSinceEpoch + _TIMER_JITTER; |
127 | 127 |
128 // Collect all pending timers. | 128 // Collect all pending timers. |
129 DoubleLinkedQueueEntry<_Timer> entry = _timers.firstEntry(); | 129 DoubleLinkedQueueEntry<_Timer> entry = _timers.firstEntry(); |
130 var pending_timers = new List(); | 130 var pending_timers = new List(); |
131 while (entry != null) { | 131 while (entry != null) { |
132 _Timer timer = entry.element; | 132 _Timer timer = entry.element; |
133 if (timer._wakeupTime <= currentTime) { | 133 if (timer._wakeupTime <= currentTime) { |
134 entry.remove(); | 134 entry.remove(); |
135 pending_timers.addLast(timer); | 135 pending_timers.add(timer); |
136 entry = _timers.firstEntry(); | 136 entry = _timers.firstEntry(); |
137 } else { | 137 } else { |
138 break; | 138 break; |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 // Trigger all of the pending timers. New timers added as part of the | 142 // Trigger all of the pending timers. New timers added as part of the |
143 // callbacks will be enqueued now and notified in the next spin at the | 143 // callbacks will be enqueued now and notified in the next spin at the |
144 // earliest. | 144 // earliest. |
145 _handling_callbacks = true; | 145 _handling_callbacks = true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 _getTimerFactoryClosure() { | 193 _getTimerFactoryClosure() { |
194 return (int milliSeconds, void callback(Timer timer), bool repeating) { | 194 return (int milliSeconds, void callback(Timer timer), bool repeating) { |
195 if (repeating) { | 195 if (repeating) { |
196 return new _Timer.repeating(milliSeconds, callback); | 196 return new _Timer.repeating(milliSeconds, callback); |
197 } | 197 } |
198 return new _Timer(milliSeconds, callback); | 198 return new _Timer(milliSeconds, callback); |
199 }; | 199 }; |
200 } | 200 } |
201 | 201 |
202 | 202 |
OLD | NEW |