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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/timer_patch.dart
diff --git a/runtime/lib/timer_patch.dart b/runtime/lib/timer_patch.dart
index d27e4e88994504df4b199b2a7e9d973dfb1d58de..a0183f6692a6b8bda639c0ae0b76292e57dd4a9d 100644
--- a/runtime/lib/timer_patch.dart
+++ b/runtime/lib/timer_patch.dart
@@ -2,23 +2,45 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+typedef void _TimerCallback0();
+typedef void _TimerCallback1(Timer timer);
+
patch class Timer {
- /* patch */ factory Timer(int milliseconds, void callback(Timer timer)) {
+ /* patch */ factory Timer(var duration, Function callback) {
+ // TODO(floitsch): remove these checks when we remove the deprecated
+ // millisecond argument and the 1-argument callback.
+ 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.
+ throw new ArgumentError(callback);
+ }
+ 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.
+ throw new ArgumentError(duration);
+ }
+ int milliseconds = duration is int ? duration : duration.inMilliseconds;
+ if (milliseconds < 0) milliseconds = 0;
+ _TimerCallback1 oneArgumentCallback =
+ callback is _TimerCallback1 ? callback : (_) { callback(); };
if (_TimerFactory._factory == null) {
throw new UnsupportedError("Timer interface not supported.");
}
- return _TimerFactory._factory(milliseconds, callback, false);
+ return _TimerFactory._factory(milliseconds, oneArgumentCallback, false);
}
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
/**
* Creates a new repeating timer. The [callback] is invoked every
* [milliseconds] millisecond until cancelled.
*/
- /* patch */ factory Timer.repeating(int milliseconds,
+ /* patch */ factory Timer.repeating(var duration,
void callback(Timer timer)) {
+ // TODO(floitsch): remove this check when we remove the deprecated
+ // millisecond argument.
+ if (duration is! Duration && duration is! int) {
+ throw new ArgumentError(duration);
+ }
if (_TimerFactory._factory == null) {
throw new UnsupportedError("Timer interface not supported.");
}
+ int milliseconds = duration is int ? duration : duration.inMilliseconds;
+ if (milliseconds < 0) milliseconds = 0;
return _TimerFactory._factory(milliseconds, callback, true);
}
}

Powered by Google App Engine
This is Rietveld 408576698