Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: sdk/lib/io/timer_impl.dart

Issue 18325006: Add isActive field on Timer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 extends LinkedListEntry<_Timer> implements Timer { 7 class _Timer extends LinkedListEntry<_Timer> implements Timer {
8 // Disables the timer. 8 // Disables the timer.
9 static const int _NO_TIMER = -1; 9 static const int _NO_TIMER = -1;
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 _Timer._internal() {} 43 _Timer._internal() {}
44 44
45 void _clear() { 45 void _clear() {
46 _callback = null; 46 _callback = null;
47 _milliSeconds = 0; 47 _milliSeconds = 0;
48 _wakeupTime = 0; 48 _wakeupTime = 0;
49 } 49 }
50 50
51 bool get _repeating => _milliSeconds >= 0; 51 bool get _repeating => _milliSeconds >= 0;
52 52
53 bool get isActive => (_callback != null);
54
53 55
54 // Cancels a set timer. The timer is removed from the timer list and if 56 // Cancels a set timer. The timer is removed from the timer list and if
55 // the given timer is the earliest timer the native timer is reset. 57 // the given timer is the earliest timer the native timer is reset.
56 void cancel() { 58 void cancel() {
57 _clear(); 59 _clear();
58 // Return if already canceled. 60 // Return if already canceled.
59 if (list == null) return; 61 if (list == null) return;
60 assert(!_timers.isEmpty); 62 assert(!_timers.isEmpty);
61 _Timer first = _timers.first; 63 _Timer first = _timers.first;
62 unlink(); 64 unlink();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Trigger all of the pending timers. New timers added as part of the 138 // Trigger all of the pending timers. New timers added as part of the
137 // callbacks will be enqueued now and notified in the next spin at the 139 // callbacks will be enqueued now and notified in the next spin at the
138 // earliest. 140 // earliest.
139 _handling_callbacks = true; 141 _handling_callbacks = true;
140 try { 142 try {
141 for (var timer in pending_timers) { 143 for (var timer in pending_timers) {
142 // One of the timers in the pending_timers list can cancel 144 // One of the timers in the pending_timers list can cancel
143 // one of the later timers which will set the callback to 145 // one of the later timers which will set the callback to
144 // null. 146 // null.
145 if (timer._callback != null) { 147 if (timer._callback != null) {
146 timer._callback(timer); 148 var callback = timer._callback;
149 if (!timer._repeating) {
150 timer._callback = null;
floitsch 2013/07/01 17:50:56 Add comment: // Mark timer as inactive.
zarah 2013/07/02 11:22:01 Done.
151 }
152 callback(timer);
147 // Re-insert repeating timer if not canceled. 153 // Re-insert repeating timer if not canceled.
148 if (timer._repeating && timer._callback != null) { 154 if (timer._repeating && timer._callback != null) {
149 timer._advanceWakeupTime(); 155 timer._advanceWakeupTime();
150 timer._addTimerToList(); 156 timer._addTimerToList();
151 } 157 }
152 } 158 }
153 } 159 }
154 } finally { 160 } finally {
155 _handling_callbacks = false; 161 _handling_callbacks = false;
156 _notifyEventHandler(); 162 _notifyEventHandler();
(...skipping 19 matching lines...) Expand all
176 _getTimerFactoryClosure() { 182 _getTimerFactoryClosure() {
177 return (int milliSeconds, void callback(Timer timer), bool repeating) { 183 return (int milliSeconds, void callback(Timer timer), bool repeating) {
178 if (repeating) { 184 if (repeating) {
179 return new _Timer.periodic(milliSeconds, callback); 185 return new _Timer.periodic(milliSeconds, callback);
180 } 186 }
181 return new _Timer(milliSeconds, callback); 187 return new _Timer(milliSeconds, callback);
182 }; 188 };
183 } 189 }
184 190
185 191
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698