| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library async.restartable_timer; | |
| 6 | |
| 7 import 'dart:async'; | 5 import 'dart:async'; |
| 8 | 6 |
| 9 /// A non-periodic timer that can be restarted any number of times. | 7 /// A non-periodic timer that can be restarted any number of times. |
| 10 /// | 8 /// |
| 11 /// Once restarted (via [reset]), the timer counts down from its original | 9 /// Once restarted (via [reset]), the timer counts down from its original |
| 12 /// duration again. | 10 /// duration again. |
| 13 class RestartableTimer implements Timer { | 11 class RestartableTimer implements Timer { |
| 14 /// The duration of the timer. | 12 /// The duration of the timer. |
| 15 final Duration _duration; | 13 final Duration _duration; |
| 16 | 14 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 39 /// This restarts the timer even if it has already fired or has been canceled. | 37 /// This restarts the timer even if it has already fired or has been canceled. |
| 40 void reset() { | 38 void reset() { |
| 41 _timer.cancel(); | 39 _timer.cancel(); |
| 42 _timer = new Timer(_duration, _callback); | 40 _timer = new Timer(_duration, _callback); |
| 43 } | 41 } |
| 44 | 42 |
| 45 void cancel() { | 43 void cancel() { |
| 46 _timer.cancel(); | 44 _timer.cancel(); |
| 47 } | 45 } |
| 48 } | 46 } |
| OLD | NEW |