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

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

Powered by Google App Engine
This is Rietveld 408576698