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

Side by Side Diff: sdk/lib/async/timer.dart

Issue 17098007: Reapply "Zone support for Futures, Timer, Streams." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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/async/zone.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 /** 9 /**
10 * Creates a new timer. 10 * Creates a new timer.
(...skipping 11 matching lines...) Expand all
22 * const ms = const Duration(milliseconds: 1); 22 * const ms = const Duration(milliseconds: 1);
23 * 23 *
24 * startTimeout([int milliseconds]) { 24 * startTimeout([int milliseconds]) {
25 * var duration = milliseconds == null ? TIMEOUT : ms * milliseconds; 25 * var duration = milliseconds == null ? TIMEOUT : ms * milliseconds;
26 * return new Timer(duration, handleTimeout); 26 * return new Timer(duration, handleTimeout);
27 * } 27 * }
28 * 28 *
29 * Note: If Dart code using Timer is compiled to JavaScript, the finest 29 * Note: If Dart code using Timer is compiled to JavaScript, the finest
30 * granularity available in the browser is 4 milliseconds. 30 * granularity available in the browser is 4 milliseconds.
31 */ 31 */
32 external factory Timer(Duration duration, void callback()); 32 factory Timer(Duration duration, void callback()) {
33 return _Zone.current.createTimer(duration, callback);
34 }
33 35
34 /** 36 /**
35 * Creates a new repeating timer. 37 * Creates a new repeating timer.
36 * 38 *
37 * The [callback] is invoked repeatedly with [duration] intervals until 39 * The [callback] is invoked repeatedly with [duration] intervals until
38 * canceled. A negative duration is treated similar to a duration of 0. 40 * canceled. A negative duration is treated similar to a duration of 0.
39 */ 41 */
40 external factory Timer.periodic(Duration duration, 42 factory Timer.periodic(Duration duration,
41 void callback(Timer timer)); 43 void callback(Timer timer)) {
44 return _Zone.current.createPeriodicTimer(duration, callback);
45 }
42 46
43 /** 47 /**
44 * Runs the given [callback] asynchronously as soon as possible. 48 * Runs the given [callback] asynchronously as soon as possible.
45 * 49 *
46 * This function is equivalent to `new Timer(Duration.ZERO, callback)`. 50 * This function is equivalent to `new Timer(Duration.ZERO, callback)`.
47 */ 51 */
48 static void run(void callback()) { 52 static void run(void callback()) {
49 new Timer(Duration.ZERO, callback); 53 new Timer(Duration.ZERO, callback);
50 } 54 }
51 55
52 /** 56 /**
53 * Cancels the timer. 57 * Cancels the timer.
54 */ 58 */
55 void cancel(); 59 void cancel();
56 } 60 }
61
62 external Timer _createTimer(Duration duration, void callback());
63 external Timer _createPeriodicTimer(Duration duration,
64 void callback(Timer timer));
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | sdk/lib/async/zone.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698