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

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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/lib/async/timer_isActive_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
53 54
54 // Cancels a set timer. The timer is removed from the timer list and if 55 // 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. 56 // the given timer is the earliest timer the native timer is reset.
56 void cancel() { 57 void cancel() {
57 _clear(); 58 _clear();
58 // Return if already canceled. 59 // Return if already canceled.
59 if (list == null) return; 60 if (list == null) return;
60 assert(!_timers.isEmpty); 61 assert(!_timers.isEmpty);
61 _Timer first = _timers.first; 62 _Timer first = _timers.first;
62 unlink(); 63 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 137 // 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 138 // callbacks will be enqueued now and notified in the next spin at the
138 // earliest. 139 // earliest.
139 _handling_callbacks = true; 140 _handling_callbacks = true;
140 try { 141 try {
141 for (var timer in pending_timers) { 142 for (var timer in pending_timers) {
142 // One of the timers in the pending_timers list can cancel 143 // One of the timers in the pending_timers list can cancel
143 // one of the later timers which will set the callback to 144 // one of the later timers which will set the callback to
144 // null. 145 // null.
145 if (timer._callback != null) { 146 if (timer._callback != null) {
146 timer._callback(timer); 147 var callback = timer._callback;
148 if (!timer._repeating) {
149 //Mark timer as inactive.
150 timer._callback = null;
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
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tests/lib/async/timer_isActive_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698