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

Unified Diff: sdk/lib/html/dartium/html_dartium.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:
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 d7bb433baf8674dc715cb60500ea248395157e9a..ea5eda658292b405edf88882a991cc5d5ce8cec8 100644
--- a/sdk/lib/html/dartium/html_dartium.dart
+++ b/sdk/lib/html/dartium/html_dartium.dart
@@ -35082,29 +35082,45 @@ 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) {
assert(msg == _TIMER_PING);
- assert(replyTo == _HELPER_ISOLATE_PORT);
callback(this);
if (!repeating) _cancel();
});
- _HELPER_ISOLATE_PORT.then((port) {
- port.send([_NEW_TIMER, milliSeconds, repeating], _sendPort);
- });
+
+ _send([_NEW_TIMER, milliSeconds, repeating]);
}
void cancel() {
_cancel();
- _HELPER_ISOLATE_PORT.then((port) {
- port.send([_CANCEL_TIMER], _sendPort);
- });
+ _send([_CANCEL_TIMER]);
}
void _cancel() {
_port.close();
}
+
+ // Tricky part.
+ // Once _HELPER_ISOLATE_PORT gets resolved, it will still delay in .then
+ // and to delay Timer.run is used. However, Timer.run will try to register
+ // another Timer and here we got stuck: event cannot be posted as then
+ // callback is not executed because it's delayed with timer.
+ // Therefore once future is resolved, it's unsafe to call .then on it
+ // in Timer code.
+ _send(msg) {
+ if (_SEND_PORT != null) {
+ _SEND_PORT.send(msg, _sendPort);
+ } else {
+ _HELPER_ISOLATE_PORT.then((port) {
+ _SEND_PORT = port;
+ _SEND_PORT.send(msg, _sendPort);
+ });
+ }
+ }
}
get _pureIsolateTimerFactoryClosure =>
@@ -36342,10 +36358,10 @@ _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();
} else if (cmd == _PRINT) {

Powered by Google App Engine
This is Rietveld 408576698