| 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 /** | 7 /** |
| 8 * A count-down timer that can be configured to fire once or repeatedly. | 8 * A count-down timer that can be configured to fire once or repeatedly. |
| 9 * | 9 * |
| 10 * The timer counts down from the specified duration to 0. | 10 * The timer counts down from the specified duration to 0. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 duration, Zone.current.bindCallback(callback, runGuarded: true)); | 53 duration, Zone.current.bindCallback(callback, runGuarded: true)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Creates a new repeating timer. | 57 * Creates a new repeating timer. |
| 58 * | 58 * |
| 59 * The [callback] is invoked repeatedly with [duration] intervals until | 59 * The [callback] is invoked repeatedly with [duration] intervals until |
| 60 * canceled with the [cancel] function. | 60 * canceled with the [cancel] function. |
| 61 */ | 61 */ |
| 62 factory Timer.periodic(Duration duration, | 62 factory Timer.periodic(Duration duration, |
| 63 void callback(Timer timer)) { | 63 void callback(Timer timer)) { |
| 64 if (Zone.current == Zone.ROOT) { | 64 if (Zone.current == Zone.ROOT) { |
| 65 // No need to bind the callback. We know that the root's timer will | 65 // No need to bind the callback. We know that the root's timer will |
| 66 // be invoked in the root zone. | 66 // be invoked in the root zone. |
| 67 return Zone.current.createPeriodicTimer(duration, callback); | 67 return Zone.current.createPeriodicTimer(duration, callback); |
| 68 } | 68 } |
| 69 return Zone.current.createPeriodicTimer( | 69 return Zone.current.createPeriodicTimer( |
| 70 duration, Zone.current.bindUnaryCallback(callback, runGuarded: true)); | 70 duration, Zone.current.bindUnaryCallback(callback, runGuarded: true)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 * and the timer has not been canceled. | 91 * and the timer has not been canceled. |
| 92 * | 92 * |
| 93 * A periodic timer is active if it has not been canceled. | 93 * A periodic timer is active if it has not been canceled. |
| 94 */ | 94 */ |
| 95 bool get isActive; | 95 bool get isActive; |
| 96 } | 96 } |
| 97 | 97 |
| 98 external Timer _createTimer(Duration duration, void callback()); | 98 external Timer _createTimer(Duration duration, void callback()); |
| 99 external Timer _createPeriodicTimer(Duration duration, | 99 external Timer _createPeriodicTimer(Duration duration, |
| 100 void callback(Timer timer)); | 100 void callback(Timer timer)); |
| OLD | NEW |