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

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

Issue 96643003: Change Future.timeout callback to a named parameter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove dartium change, reduce safetyMargin for VM to 0. Created 7 years 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 | « no previous file | tests/lib/async/multiple_timer_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
11 // Timers are ordered by wakeup time. 11 // Timers are ordered by wakeup time.
12 static LinkedList<_Timer> _timers = new LinkedList<_Timer>(); 12 static LinkedList<_Timer> _timers = new LinkedList<_Timer>();
13 13
14 static RawReceivePort _receivePort; 14 static RawReceivePort _receivePort;
15 static bool _handling_callbacks = false; 15 static bool _handling_callbacks = false;
16 16
17 Function _callback; 17 Function _callback;
18 int _milliSeconds; 18 int _milliSeconds;
19 int _wakeupTime = 0; 19 int _wakeupTime = 0;
20 20
21 static Timer _createTimer(void callback(Timer timer), 21 static Timer _createTimer(void callback(Timer timer),
22 int milliSeconds, 22 int milliSeconds,
23 bool repeating) { 23 bool repeating) {
24 _Timer timer = new _Timer._internal(); 24 _Timer timer = new _Timer._internal();
25 timer._callback = callback; 25 timer._callback = callback;
26 if (milliSeconds > 0) { 26 if (milliSeconds > 0) {
27 // Add one because DateTime.now() is assumed to round down
28 // to nearest millisecond, not up, so that time + duration is before
29 // duration milliseconds from now. Using micosecond timers like
30 // Stopwatch allows detecting that the timer fires early.
27 timer._wakeupTime = 31 timer._wakeupTime =
28 new DateTime.now().millisecondsSinceEpoch + milliSeconds; 32 new DateTime.now().millisecondsSinceEpoch + 1 + milliSeconds;
29 } 33 }
30 timer._milliSeconds = repeating ? milliSeconds : -1; 34 timer._milliSeconds = repeating ? milliSeconds : -1;
31 timer._addTimerToList(); 35 timer._addTimerToList();
32 if (identical(timer, _timers.first)) { 36 if (identical(timer, _timers.first)) {
33 // The new timer is the first in queue. Update event handler. 37 // The new timer is the first in queue. Update event handler.
34 timer._notifyEventHandler(); 38 timer._notifyEventHandler();
35 } 39 }
36 return timer; 40 return timer;
37 } 41 }
38 42
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 _getTimerFactoryClosure() { 192 _getTimerFactoryClosure() {
189 return (int milliSeconds, void callback(Timer timer), bool repeating) { 193 return (int milliSeconds, void callback(Timer timer), bool repeating) {
190 if (repeating) { 194 if (repeating) {
191 return new _Timer.periodic(milliSeconds, callback); 195 return new _Timer.periodic(milliSeconds, callback);
192 } 196 }
193 return new _Timer(milliSeconds, callback); 197 return new _Timer(milliSeconds, callback);
194 }; 198 };
195 } 199 }
196 200
197 201
OLDNEW
« no previous file with comments | « no previous file | tests/lib/async/multiple_timer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698