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

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

Issue 13430008: Only use special method to send messages to helper isolate. (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
« no previous file with comments | « tools/dom/src/Timer.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/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index ccf4ba31cd2e4a7acf93f6a77fd8d4198e13153d..89e4f726d7b5e8ced72b48c969b9cb13af5ae8c1 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -132,9 +132,29 @@ class _DOMStringMap extends NativeFieldWrapperClass1 implements Map<String, Stri
bool get isEmpty => Maps.isEmpty(this);
}
-final Future<SendPort> _HELPER_ISOLATE_PORT =
+final Future<SendPort> __HELPER_ISOLATE_PORT =
spawnDomFunction(_helperIsolateMain);
+// 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.
+SendPort __SEND_PORT;
+
+_sendToHelperIsolate(msg, SendPort replyTo) {
+ if (__SEND_PORT != null) {
+ __SEND_PORT.send(msg, replyTo);
+ } else {
+ __HELPER_ISOLATE_PORT.then((port) {
+ __SEND_PORT = port;
+ __SEND_PORT.send(msg, replyTo);
+ });
+ }
+}
+
final _TIMER_REGISTRY = new Map<SendPort, Timer>();
const _NEW_TIMER = 'NEW_TIMER';
@@ -164,9 +184,7 @@ _helperIsolateMain() {
final _printClosure = window.console.log;
final _pureIsolatePrintClosure = (s) {
- _HELPER_ISOLATE_PORT.then((sendPort) {
- sendPort.send([_PRINT, s]);
- });
+ _sendToHelperIsolate([_PRINT, s]);
};
final _forwardingPrintClosure = _Utils.forwardingPrint;
« no previous file with comments | « tools/dom/src/Timer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698