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

Side by Side Diff: runtime/lib/timer_patch.dart

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use stopwatch. Created 7 years, 10 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 typedef void _TimerCallback0();
6 typedef void _TimerCallback1(Timer timer);
7
5 patch class Timer { 8 patch class Timer {
6 /* patch */ factory Timer(int milliseconds, void callback(Timer timer)) { 9 /* patch */ factory Timer(var duration, Function callback) {
10 // TODO(floitsch): remove these checks when we remove the deprecated
11 // millisecond argument and the 1-argument callback.
12 if (callback is! _TimerCallback0 && callback is! _TimerCallback1) {
Lasse Reichstein Nielsen 2013/02/11 13:01:21 Does this work in dart2js?
floitsch 2013/02/11 19:21:32 It should. I tested it for dart2js.
13 throw new ArgumentError(callback);
14 }
15 if (duration is! Duration && duration is! int) {
Lasse Reichstein Nielsen 2013/02/11 13:01:21 Don't check for Duration, just assume it if it isn
floitsch 2013/02/11 19:21:32 Done.
16 throw new ArgumentError(duration);
17 }
18 int milliseconds = duration is int ? duration : duration.inMilliseconds;
19 if (milliseconds < 0) milliseconds = 0;
20 _TimerCallback1 oneArgumentCallback =
21 callback is _TimerCallback1 ? callback : (_) { callback(); };
7 if (_TimerFactory._factory == null) { 22 if (_TimerFactory._factory == null) {
8 throw new UnsupportedError("Timer interface not supported."); 23 throw new UnsupportedError("Timer interface not supported.");
9 } 24 }
10 return _TimerFactory._factory(milliseconds, callback, false); 25 return _TimerFactory._factory(milliseconds, oneArgumentCallback, false);
11 } 26 }
Lasse Reichstein Nielsen 2013/02/11 13:01:21 Why is this code in a patch file? Everything excep
floitsch 2013/02/11 19:21:32 Filed http://dartbug.com/8467
12 27
13 /** 28 /**
14 * Creates a new repeating timer. The [callback] is invoked every 29 * Creates a new repeating timer. The [callback] is invoked every
15 * [milliseconds] millisecond until cancelled. 30 * [milliseconds] millisecond until cancelled.
16 */ 31 */
17 /* patch */ factory Timer.repeating(int milliseconds, 32 /* patch */ factory Timer.repeating(var duration,
18 void callback(Timer timer)) { 33 void callback(Timer timer)) {
34 // TODO(floitsch): remove this check when we remove the deprecated
35 // millisecond argument.
36 if (duration is! Duration && duration is! int) {
37 throw new ArgumentError(duration);
38 }
19 if (_TimerFactory._factory == null) { 39 if (_TimerFactory._factory == null) {
20 throw new UnsupportedError("Timer interface not supported."); 40 throw new UnsupportedError("Timer interface not supported.");
21 } 41 }
42 int milliseconds = duration is int ? duration : duration.inMilliseconds;
43 if (milliseconds < 0) milliseconds = 0;
22 return _TimerFactory._factory(milliseconds, callback, true); 44 return _TimerFactory._factory(milliseconds, callback, true);
23 } 45 }
24 } 46 }
25 47
26 typedef Timer _TimerFactoryClosure(int milliseconds, 48 typedef Timer _TimerFactoryClosure(int milliseconds,
27 void callback(Timer timer), 49 void callback(Timer timer),
28 bool repeating); 50 bool repeating);
29 51
30 class _TimerFactory { 52 class _TimerFactory {
31 static _TimerFactoryClosure _factory; 53 static _TimerFactoryClosure _factory;
32 } 54 }
33 55
34 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets 56 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets
35 // [_TimerFactory._factory] directly. 57 // [_TimerFactory._factory] directly.
36 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { 58 void _setTimerFactoryClosure(_TimerFactoryClosure closure) {
37 _TimerFactory._factory = closure; 59 _TimerFactory._factory = closure;
38 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698