Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: tools/dom/src/native_DOMImplementation.dart

Issue 18325006: Add isActive field on Timer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« tests/lib/async/timer_isActive_test.dart ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index 89f139410824c907f28b772ff438896480913901..1d6ae20e8bf655d2f9c9e394a0d129f6c64559a8 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -200,29 +200,43 @@ final _forwardingPrintClosure = _Utils.forwardingPrint;
class _Timer implements Timer {
final canceller;
+ bool _isDone = false;
_Timer(this.canceller);
- void cancel() { canceller(); }
-}
+ factory _Timer.timerFactoryClosure(int milliSeconds,
floitsch 2013/07/01 17:50:56 Make this the default constructor. If you use the
zarah 2013/07/02 11:22:01 Done.
+ void callback(Timer timer),
+ bool repeating) {
+ var maker;
+ var canceller;
+ if (repeating) {
+ maker = window._setInterval;
+ canceller = window._clearInterval;
+ } else {
+ maker = window._setTimeout;
+ canceller = window._clearTimeout;
+ }
+ Timer timer;
+ final int id = maker(() { _isDone = true; callback(timer);}, milliSeconds);
floitsch 2013/07/01 17:50:56 Don't put more than one statement on the same line
zarah 2013/07/02 11:22:01 Done.
+ timer = new _Timer(() { canceller(id); });
floitsch 2013/07/01 17:50:56 Nit: it is annoying to me that we wrap the cancele
zarah 2013/07/02 11:22:01 Done.
+ return timer;
+ }
-get _timerFactoryClosure => (int milliSeconds, void callback(Timer timer), bool repeating) {
- var maker;
- var canceller;
- if (repeating) {
- maker = window._setInterval;
- canceller = window._clearInterval;
- } else {
- maker = window._setTimeout;
- canceller = window._clearTimeout;
+ void cancel() {
+ _isDone = true;
+ canceller();
}
- Timer timer;
- final int id = maker(() { callback(timer); }, milliSeconds);
- timer = new _Timer(() { canceller(id); });
- return timer;
+
+ bool get isActive => !_isDone;
+}
+
+get _timerFactoryClosure =>
+ (int milliSeconds, void callback(Timer timer), bool repeating) {
+ return _Timer.timerFactoryClosure(milliseconds, callback, repeating);
};
class _PureIsolateTimer implements Timer {
+ bool _isDone = false;
final ReceivePort _port = new ReceivePort();
SendPort _sendPort; // Effectively final.
@@ -232,6 +246,7 @@ class _PureIsolateTimer implements Timer {
_sendPort = _port.toSendPort();
_port.receive((msg, replyTo) {
assert(msg == _TIMER_PING);
+ _isDone = !repeating;
callback(this);
if (!repeating) _cancel();
});
@@ -245,12 +260,15 @@ class _PureIsolateTimer implements Timer {
}
void _cancel() {
+ _isDone = true;
_port.close();
}
_send(msg) {
_sendToHelperIsolate(msg, _sendPort);
}
+
+ bool get isActive => !_isDone;
}
get _pureIsolateTimerFactoryClosure =>
« tests/lib/async/timer_isActive_test.dart ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698