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

Unified Diff: sdk/lib/html/dartium/html_dartium.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:
Download patch
Index: sdk/lib/html/dartium/html_dartium.dart
diff --git a/sdk/lib/html/dartium/html_dartium.dart b/sdk/lib/html/dartium/html_dartium.dart
index 81f000f1ece763388a2bd7f83b60f49339edfd7d..132b803a12982695b47422f4774478d60ec13e6f 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -31021,29 +31021,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,
+ 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);
+ timer = new _Timer(() { canceller(id); });
+ 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.
@@ -31053,6 +31067,7 @@ class _PureIsolateTimer implements Timer {
_sendPort = _port.toSendPort();
_port.receive((msg, replyTo) {
assert(msg == _TIMER_PING);
+ _isDone = !repeating;
callback(this);
if (!repeating) _cancel();
});
@@ -31066,12 +31081,15 @@ class _PureIsolateTimer implements Timer {
}
void _cancel() {
+ _isDone = true;
_port.close();
}
_send(msg) {
_sendToHelperIsolate(msg, _sendPort);
}
+
+ bool get isActive => !_isDone;
}
get _pureIsolateTimerFactoryClosure =>

Powered by Google App Engine
This is Rietveld 408576698