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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/async_patch.dart

Issue 12213092: Rework Timer interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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: sdk/lib/_internal/compiler/implementation/lib/async_patch.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart b/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart
index 0fccce2a432b6eb93bf2af79f0d317545e165f69..0e0a70d2e4620d53530b8b8eb24c3f0b2809d2d2 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart
@@ -6,16 +6,35 @@
import 'dart:_isolate_helper' show TimerImpl;
+typedef void _TimerCallback0();
+typedef void _TimerCallback1(Timer timer);
+
patch class Timer {
- patch factory Timer(int milliseconds, void callback(Timer timer)) {
- return new TimerImpl(milliseconds, callback);
+ patch factory Timer(var duration, var callback) {
+ // TODO(floitsch): remove these checks when we remove the deprecated
+ // millisecond argument and the 1-argument callback. Also remove the
+ // int-test below.
+ if (callback is! _TimerCallback0 && callback is! _TimerCallback1) {
+ throw new ArgumentError(callback);
+ }
+ int milliseconds = duration is int ? duration : duration.inMilliseconds;
+ if (milliseconds < 0) milliseconds = 0;
+ Timer timer;
+ _TimerCallback0 zeroArgumentCallback =
+ callback is _TimerCallback0 ? callback : () => callback(timer);
+ timer = new TimerImpl(milliseconds, zeroArgumentCallback);
+ return timer;
}
/**
* Creates a new repeating timer. The [callback] is invoked every
* [milliseconds] millisecond until cancelled.
*/
- patch factory Timer.repeating(int milliseconds, void callback(Timer timer)) {
+ patch factory Timer.repeating(var duration, void callback(Timer timer)) {
+ // TODO(floitsch): remove this check when we remove the deprecated
+ // millisecond argument.
+ int milliseconds = duration is int ? duration : duration.inMilliseconds;
+ if (milliseconds < 0) milliseconds = 0;
return new TimerImpl.repeating(milliseconds, callback);
}
}
« no previous file with comments | « samples/chat/chat_server_lib.dart ('k') | sdk/lib/_internal/compiler/implementation/lib/isolate_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698