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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/dom/src/Timer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of html; 5 part of html;
6 6
7 class _Utils { 7 class _Utils {
8 static double dateTimeToDouble(DateTime dateTime) => 8 static double dateTimeToDouble(DateTime dateTime) =>
9 dateTime.millisecondsSinceEpoch.toDouble(); 9 dateTime.millisecondsSinceEpoch.toDouble();
10 static DateTime doubleToDateTime(double dateTime) { 10 static DateTime doubleToDateTime(double dateTime) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 String putIfAbsent(String key, String ifAbsent()) => Maps.putIfAbsent(this, ke y, ifAbsent); 125 String putIfAbsent(String key, String ifAbsent()) => Maps.putIfAbsent(this, ke y, ifAbsent);
126 String remove(String key) native "DOMStringMap_remove_Callback"; 126 String remove(String key) native "DOMStringMap_remove_Callback";
127 void clear() => Maps.clear(this); 127 void clear() => Maps.clear(this);
128 void forEach(void f(String key, String value)) => Maps.forEach(this, f); 128 void forEach(void f(String key, String value)) => Maps.forEach(this, f);
129 Collection<String> get keys native "DOMStringMap_getKeys_Callback"; 129 Collection<String> get keys native "DOMStringMap_getKeys_Callback";
130 Collection<String> get values => Maps.getValues(this); 130 Collection<String> get values => Maps.getValues(this);
131 int get length => Maps.length(this); 131 int get length => Maps.length(this);
132 bool get isEmpty => Maps.isEmpty(this); 132 bool get isEmpty => Maps.isEmpty(this);
133 } 133 }
134 134
135 final Future<SendPort> _HELPER_ISOLATE_PORT = 135 final Future<SendPort> __HELPER_ISOLATE_PORT =
136 spawnDomFunction(_helperIsolateMain); 136 spawnDomFunction(_helperIsolateMain);
137 137
138 // Tricky part.
139 // Once _HELPER_ISOLATE_PORT gets resolved, it will still delay in .then
vsm 2013/04/02 16:08:31 Extra _ prefix to match the new name. BTW, do we
Anton Muhin 2013/04/02 16:17:49 It's my personal invention and probably I shouldn'
140 // and to delay Timer.run is used. However, Timer.run will try to register
141 // another Timer and here we got stuck: event cannot be posted as then
142 // callback is not executed because it's delayed with timer.
143 // Therefore once future is resolved, it's unsafe to call .then on it
144 // in Timer code.
145 SendPort __SEND_PORT;
146
147 _sendToHelperIsolate(msg, SendPort replyTo) {
148 if (__SEND_PORT != null) {
149 __SEND_PORT.send(msg, replyTo);
150 } else {
151 __HELPER_ISOLATE_PORT.then((port) {
152 __SEND_PORT = port;
153 __SEND_PORT.send(msg, replyTo);
154 });
155 }
156 }
157
138 final _TIMER_REGISTRY = new Map<SendPort, Timer>(); 158 final _TIMER_REGISTRY = new Map<SendPort, Timer>();
139 159
140 const _NEW_TIMER = 'NEW_TIMER'; 160 const _NEW_TIMER = 'NEW_TIMER';
141 const _CANCEL_TIMER = 'CANCEL_TIMER'; 161 const _CANCEL_TIMER = 'CANCEL_TIMER';
142 const _TIMER_PING = 'TIMER_PING'; 162 const _TIMER_PING = 'TIMER_PING';
143 const _PRINT = 'PRINT'; 163 const _PRINT = 'PRINT';
144 164
145 _helperIsolateMain() { 165 _helperIsolateMain() {
146 port.receive((msg, replyTo) { 166 port.receive((msg, replyTo) {
147 final cmd = msg[0]; 167 final cmd = msg[0];
148 if (cmd == _NEW_TIMER) { 168 if (cmd == _NEW_TIMER) {
149 final duration = new Duration(milliseconds: msg[1]); 169 final duration = new Duration(milliseconds: msg[1]);
150 bool periodic = msg[2]; 170 bool periodic = msg[2];
151 ping() { replyTo.send(_TIMER_PING); }; 171 ping() { replyTo.send(_TIMER_PING); };
152 _TIMER_REGISTRY[replyTo] = periodic ? 172 _TIMER_REGISTRY[replyTo] = periodic ?
153 new Timer.periodic(duration, (_) { ping(); }) : 173 new Timer.periodic(duration, (_) { ping(); }) :
154 new Timer(duration, ping); 174 new Timer(duration, ping);
155 } else if (cmd == _CANCEL_TIMER) { 175 } else if (cmd == _CANCEL_TIMER) {
156 _TIMER_REGISTRY.remove(replyTo).cancel(); 176 _TIMER_REGISTRY.remove(replyTo).cancel();
157 } else if (cmd == _PRINT) { 177 } else if (cmd == _PRINT) {
158 final message = msg[1]; 178 final message = msg[1];
159 // TODO(antonm): we need somehow identify those isolates. 179 // TODO(antonm): we need somehow identify those isolates.
160 print('[From isolate] $message'); 180 print('[From isolate] $message');
161 } 181 }
162 }); 182 });
163 } 183 }
164 184
165 final _printClosure = window.console.log; 185 final _printClosure = window.console.log;
166 final _pureIsolatePrintClosure = (s) { 186 final _pureIsolatePrintClosure = (s) {
167 _HELPER_ISOLATE_PORT.then((sendPort) { 187 _sendToHelperIsolate([_PRINT, s]);
168 sendPort.send([_PRINT, s]);
169 });
170 }; 188 };
171 189
172 final _forwardingPrintClosure = _Utils.forwardingPrint; 190 final _forwardingPrintClosure = _Utils.forwardingPrint;
OLDNEW
« 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