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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.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
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | tests/html/async_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 018b8aa93a10c2ead94f064616a433dc50934513..06214ba0e495c06983329e4ede952ecc08942a29 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -32785,29 +32785,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 =>
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | tests/html/async_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698