| OLD | NEW |
| 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 Loading... |
| 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 factory Timer(Duration duration, void callback()) { | 32 external factory Timer(Duration duration, void callback()); |
| 33 return _Zone.current.createTimer(duration, callback); | |
| 34 } | |
| 35 | 33 |
| 36 /** | 34 /** |
| 37 * Creates a new repeating timer. | 35 * Creates a new repeating timer. |
| 38 * | 36 * |
| 39 * The [callback] is invoked repeatedly with [duration] intervals until | 37 * The [callback] is invoked repeatedly with [duration] intervals until |
| 40 * canceled. A negative duration is treated similar to a duration of 0. | 38 * canceled. A negative duration is treated similar to a duration of 0. |
| 41 */ | 39 */ |
| 42 factory Timer.periodic(Duration duration, | 40 external factory Timer.periodic(Duration duration, |
| 43 void callback(Timer timer)) { | 41 void callback(Timer timer)); |
| 44 return _Zone.current.createPeriodicTimer(duration, callback); | |
| 45 } | |
| 46 | 42 |
| 47 /** | 43 /** |
| 48 * Runs the given [callback] asynchronously as soon as possible. | 44 * Runs the given [callback] asynchronously as soon as possible. |
| 49 * | 45 * |
| 50 * This function is equivalent to `new Timer(Duration.ZERO, callback)`. | 46 * This function is equivalent to `new Timer(Duration.ZERO, callback)`. |
| 51 */ | 47 */ |
| 52 static void run(void callback()) { | 48 static void run(void callback()) { |
| 53 new Timer(Duration.ZERO, callback); | 49 new Timer(Duration.ZERO, callback); |
| 54 } | 50 } |
| 55 | 51 |
| 56 /** | 52 /** |
| 57 * Cancels the timer. | 53 * Cancels the timer. |
| 58 */ | 54 */ |
| 59 void cancel(); | 55 void cancel(); |
| 60 } | 56 } |
| 61 | |
| 62 external Timer _createTimer(Duration duration, void callback()); | |
| 63 external Timer _createPeriodicTimer(Duration duration, | |
| 64 void callback(Timer timer)); | |
| OLD | NEW |