| 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 // Internal list used to group Timer.run callbacks. | 8 // Internal list used to group Timer.run callbacks. |
| 9 static List _runCallbacks = []; | 9 static List _runCallbacks = []; |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 * } | 29 * } |
| 30 */ | 30 */ |
| 31 external factory Timer(Duration duration, void callback()); | 31 external factory Timer(Duration duration, void callback()); |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Creates a new repeating timer. | 34 * Creates a new repeating timer. |
| 35 * | 35 * |
| 36 * The [callback] is invoked repeatedly with [duration] intervals until | 36 * The [callback] is invoked repeatedly with [duration] intervals until |
| 37 * canceled. A negative duration is treated similar to a duration of 0. | 37 * canceled. A negative duration is treated similar to a duration of 0. |
| 38 */ | 38 */ |
| 39 external factory Timer.repeating(Duration duration, | 39 external factory Timer.periodic(Duration duration, |
| 40 void callback(Timer timer)); | 40 void callback(Timer timer)); |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Runs the given [callback] asynchronously as soon as possible. | 43 * Runs the given [callback] asynchronously as soon as possible. |
| 44 */ | 44 */ |
| 45 static void run(void callback()) { | 45 static void run(void callback()) { |
| 46 // Optimizing a group of Timer.run callbacks to be executed in the | 46 // Optimizing a group of Timer.run callbacks to be executed in the |
| 47 // same Timer callback. | 47 // same Timer callback. |
| 48 _runCallbacks.add(callback); | 48 _runCallbacks.add(callback); |
| 49 if (_runCallbacks.length == 1) { | 49 if (_runCallbacks.length == 1) { |
| 50 new Timer(const Duration(milliseconds: 0), () { | 50 new Timer(const Duration(milliseconds: 0), () { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 } | 68 } |
| 69 }); | 69 }); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Cancels the timer. | 74 * Cancels the timer. |
| 75 */ | 75 */ |
| 76 void cancel(); | 76 void cancel(); |
| 77 } | 77 } |
| OLD | NEW |