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

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

Issue 13308002: Add a test for timers in child isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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/html/async_test.dart ('K') | « tests/html/async_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/Timer.dart
diff --git a/tools/dom/src/Timer.dart b/tools/dom/src/Timer.dart
index 43a208afe0a43f0a43360e1361ec6cc656f1d36b..9fa22617829bb7960851264f2c22d8ae0dee7ae9 100644
--- a/tools/dom/src/Timer.dart
+++ b/tools/dom/src/Timer.dart
@@ -37,6 +37,8 @@ class _PureIsolateTimer implements Timer {
final ReceivePort _port = new ReceivePort();
SendPort _sendPort; // Effectively final.
+ static SendPort _SEND_PORT;
+
_PureIsolateTimer(int milliSeconds, callback, repeating) {
_sendPort = _port.toSendPort();
_port.receive((msg, replyTo) {
@@ -45,9 +47,22 @@ class _PureIsolateTimer implements Timer {
callback(this);
if (!repeating) _cancel();
});
- _HELPER_ISOLATE_PORT.then((port) {
- port.send([_NEW_TIMER, milliSeconds, repeating], _sendPort);
- });
+
+ registerTimer() {
+ _SEND_PORT.send([_NEW_TIMER, milliSeconds, repeating], _sendPort);
+ }
+
+ // Tricky part: Future.then is always delayed might prevent
+ // new timer registration if many events come to this isolate.
+ // Therefore, let's resort to then only if really necessary.
vsm 2013/03/29 14:37:39 I'm confused by this. What was the problem you we
Anton Muhin 2013/03/29 16:09:15 (whatever outcome of our discuss be, I need to mod
vsm 2013/03/29 17:34:36 I think I'm starting to get this - was the old cod
Anton Muhin 2013/04/01 14:52:57 I've updated the comment. May you, please, tell m
+ if (_SEND_PORT != null) {
+ registerTimer();
+ } else {
+ _HELPER_ISOLATE_PORT.then((port) {
+ _SEND_PORT = port;
+ registerTimer();
+ });
+ }
}
void cancel() {
@@ -73,12 +88,13 @@ _helperIsolateMain() {
if (cmd == _NEW_TIMER) {
final duration = new Duration(milliseconds: msg[1]);
bool periodic = msg[2];
- final callback = () { replyTo.send(_TIMER_PING); };
+ ping() { replyTo.send(_TIMER_PING); }
_TIMER_REGISTRY[replyTo] = periodic ?
- new Timer.periodic(duration, callback) :
- new Timer(duration, callback);
+ new Timer.periodic(duration, (_) { ping(); }) :
+ new Timer(duration, ping);
} else if (cmd == _CANCEL_TIMER) {
- _TIMER_REGISTRY.remove(replyTo).cancel();
+ Timer timer = _TIMER_REGISTRY.remove(replyTo);
+ if (timer != null) timer.cancel();
}
});
}
« tests/html/async_test.dart ('K') | « tests/html/async_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698