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

Side by Side Diff: sdk/lib/async/timer.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 part of dart.async; 5 part of dart.async;
6 6
7 abstract class Timer { 7 abstract class Timer {
8 /** 8 /**
9 * Creates a new timer. The [callback] callback is invoked after 9 * Runs the given [callback] asynchronously as soon as possible.
10 * [milliseconds] milliseconds. 10 *
11 * Returns a [Timer] that can be cancelled if the callback is not necessary
12 * anymore.
11 */ 13 */
12 external factory Timer(int milliseconds, void callback(Timer timer)); 14 static Timer run(void callback()) {
Lasse Reichstein Nielsen 2013/02/11 13:01:21 Static methods below constructors.
floitsch 2013/02/11 19:21:32 Done.
15 return new Timer(const Duration(), callback);
16 }
13 17
14 /** 18 /**
15 * Creates a new repeating timer. The [callback] is invoked every 19 * Creates a new timer.
16 * [milliseconds] millisecond until cancelled. 20 *
21 * The [callback] callback is invoked after the given [duration]
22 * (a [Duration]) has passed. A negative duration is treated similar to
23 * a duration of 0.
24 *
25 * If the [duration] is statically known to be 0, consider using [run].
26 *
27 * Frequently the [duration] is either a constant or computed as in the
28 * following example (taking advantage of the multiplication operator of
29 * the Duration class):
30 *
31 * const TIMEOUT = const Duration(seconds: 3);
32 * const ms = const Duration(milliseconds: 1);
33 *
34 * startTimeout([int milliseconds]) {
35 * var duration = milliseconds == null ? TIMEOUT : ms * milliseconds;
36 * return new Timer(duration, handleTimeout);
37 * }
38 *
39 * *Deprecation warning*: this constructor used to take an [int] (the time
40 * in milliseconds) and a callback with one argument (the timer). This has
41 * changed to a [Duration] and a callback without arguments.
17 */ 42 */
18 external factory Timer.repeating(int milliseconds, 43 // TODO(floitsch): add types.
44 external factory Timer(var duration, Function callback);
45
46 /**
47 * Creates a new repeating timer.
48 *
49 * The [callback] is invoked repeatedly with [duration] intervals until
50 * canceled. A negative duration is treated similar to a duration of 0.
51 *
52 * *Deprecation warning*: this constructor used to take an [int] (the time
53 * in milliseconds). This has changed to a [Duration].
54 */
55 external factory Timer.repeating(var duration,
19 void callback(Timer timer)); 56 void callback(Timer timer));
20 57
21 /** 58 /**
22 * Cancels the timer. 59 * Cancels the timer.
23 */ 60 */
24 void cancel(); 61 void cancel();
25 } 62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698