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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 * when the previous callback started, or when the previous callback was | 69 * when the previous callback started, or when the previous callback was |
70 * scheduled for - even if the actual callback was delayed. | 70 * scheduled for - even if the actual callback was delayed. |
71 */ | 71 */ |
72 factory Timer.periodic(Duration duration, | 72 factory Timer.periodic(Duration duration, |
73 void callback(Timer timer)) { | 73 void callback(Timer timer)) { |
74 if (Zone.current == Zone.ROOT) { | 74 if (Zone.current == Zone.ROOT) { |
75 // No need to bind the callback. We know that the root's timer will | 75 // No need to bind the callback. We know that the root's timer will |
76 // be invoked in the root zone. | 76 // be invoked in the root zone. |
77 return Zone.current.createPeriodicTimer(duration, callback); | 77 return Zone.current.createPeriodicTimer(duration, callback); |
78 } | 78 } |
79 return Zone.current.createPeriodicTimer( | 79 // TODO(floitsch): the return type should be 'void', and the type |
80 duration, Zone.current.bindUnaryCallback(callback, runGuarded: true)); | 80 // should be inferred. |
| 81 var boundCallback = Zone.current.bindUnaryCallback/*<dynamic, Timer>*/( |
| 82 callback, runGuarded: true); |
| 83 return Zone.current.createPeriodicTimer(duration, boundCallback); |
81 } | 84 } |
82 | 85 |
83 /** | 86 /** |
84 * Runs the given [callback] asynchronously as soon as possible. | 87 * Runs the given [callback] asynchronously as soon as possible. |
85 * | 88 * |
86 * This function is equivalent to `new Timer(Duration.ZERO, callback)`. | 89 * This function is equivalent to `new Timer(Duration.ZERO, callback)`. |
87 */ | 90 */ |
88 static void run(void callback()) { | 91 static void run(void callback()) { |
89 new Timer(Duration.ZERO, callback); | 92 new Timer(Duration.ZERO, callback); |
90 } | 93 } |
(...skipping 11 matching lines...) Expand all Loading... |
102 * | 105 * |
103 * A periodic timer is active if it has not been canceled. | 106 * A periodic timer is active if it has not been canceled. |
104 */ | 107 */ |
105 bool get isActive; | 108 bool get isActive; |
106 | 109 |
107 external static Timer _createTimer(Duration duration, void callback()); | 110 external static Timer _createTimer(Duration duration, void callback()); |
108 external static Timer _createPeriodicTimer(Duration duration, | 111 external static Timer _createPeriodicTimer(Duration duration, |
109 void callback(Timer timer)); | 112 void callback(Timer timer)); |
110 } | 113 } |
111 | 114 |
OLD | NEW |