OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library async.reset_timer; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 /// A non-periodic timer that can be reset. | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
"reset" isn't a very descriptive word, it doesn't
nweiz
2015/10/27 21:08:12
I chose "reset" because it's already used by a num
Lasse Reichstein Nielsen
2015/10/28 09:51:02
I have no problem with "reset" as the name of the
nweiz
2015/10/28 21:10:43
Done.
| |
10 class ResetTimer implements Timer { | |
11 /// The duration of the timer. | |
12 final Duration _duration; | |
13 | |
14 /// The callback to call when the timer fires. | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Would it be useful to make the callback settable?
nweiz
2015/10/27 21:08:12
I don't think so; if that's what you want, just ho
| |
15 final ZoneCallback _callback; | |
16 | |
17 /// The inner timer. | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Being "inner" doesn't say anything about the role
nweiz
2015/10/27 21:08:12
Done.
| |
18 /// | |
19 /// This is canceled and re-created every time this is reset. | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Two uses of "this" referring to different things.
nweiz
2015/10/27 21:08:12
Done.
| |
20 Timer _timer; | |
21 | |
22 bool get isActive => _timer.isActive; | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Move getter below constructor.
nweiz
2015/10/27 21:08:12
Done.
| |
23 | |
24 /// Creates a new timer. | |
25 /// | |
26 /// The [callback] function is invoked after the given [duration]. Unlike a | |
27 /// normal non-periodic [Timer], [callback] may be called more than once. | |
28 ResetTimer(this._duration, this._callback) { | |
29 _timer = new Timer(_duration, _callback); | |
30 } | |
31 | |
32 /// Resets the timer so that it starts counting from its original duration aga in. | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Resets -> restarts.
The "reset" name is fine for t
Lasse Reichstein Nielsen
2015/10/27 09:45:14
long line.
so that it starts ... -> and starts co
nweiz
2015/10/27 21:08:12
Done.
nweiz
2015/10/27 21:08:12
Done.
| |
33 /// | |
34 /// This resets the timer even if it's already fired or has been canceled. | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
resets -> restarts
it's -> it has
nweiz
2015/10/27 21:08:12
Done.
| |
35 void reset() { | |
36 _timer.cancel(); | |
37 _timer = new Timer(_duration, _callback); | |
38 } | |
39 | |
40 void cancel() { | |
41 _timer.cancel(); | |
42 } | |
43 } | |
OLD | NEW |