OLD | NEW |
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 patch class ReceivePort { | 5 patch class ReceivePort { |
6 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 6 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
7 | 7 |
8 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = | 8 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = |
9 _ReceivePortImpl.fromRawReceivePort; | 9 _ReceivePortImpl.fromRawReceivePort; |
10 } | 10 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 /* patch */ static Future<Isolate> spawn( | 187 /* patch */ static Future<Isolate> spawn( |
188 void entryPoint(message), var message) { | 188 void entryPoint(message), var message) { |
189 Completer completer = new Completer<Isolate>.sync(); | 189 Completer completer = new Completer<Isolate>.sync(); |
190 try { | 190 try { |
191 // The VM will invoke [_startIsolate] with entryPoint as argument. | 191 // The VM will invoke [_startIsolate] with entryPoint as argument. |
192 SendPort controlPort = _Isolate._spawnFunction(entryPoint); | 192 SendPort controlPort = _Isolate._spawnFunction(entryPoint); |
193 RawReceivePort readyPort = new RawReceivePort(); | 193 RawReceivePort readyPort = new RawReceivePort(); |
194 controlPort.send([message, readyPort.sendPort]); | 194 controlPort.send([message, readyPort.sendPort]); |
195 readyPort.handler = (_) { | 195 readyPort.handler = (_) { |
196 readyPort.close(); | 196 readyPort.close(); |
197 completer.complete(new Isolate._fromControlPort(controlPort)); | 197 completer.complete(new Isolate.fromControlPort(controlPort)); |
198 }; | 198 }; |
199 } catch(e, st) { | 199 } catch(e, st) { |
200 // TODO(floitsch): we want errors to go into the returned future. | 200 // TODO(floitsch): we want errors to go into the returned future. |
201 rethrow; | 201 rethrow; |
202 }; | 202 }; |
203 return completer.future; | 203 return completer.future; |
204 } | 204 } |
205 | 205 |
206 /* patch */ static Future<Isolate> spawnUri(Uri uri, var message) { | 206 /* patch */ static Future<Isolate> spawnUri(Uri uri, var message) { |
207 Completer completer = new Completer<Isolate>.sync(); | 207 Completer completer = new Completer<Isolate>.sync(); |
208 try { | 208 try { |
209 // The VM will invoke [_startIsolate]. | 209 // The VM will invoke [_startIsolate]. |
210 SendPort controlPort = _Isolate._spawnUri(uri.path); | 210 SendPort controlPort = _Isolate._spawnUri(uri.path); |
211 RawReceivePort readyPort = new RawReceivePort(); | 211 RawReceivePort readyPort = new RawReceivePort(); |
212 controlPort.send([message, readyPort.sendPort]); | 212 controlPort.send([message, readyPort.sendPort]); |
213 readyPort.handler = (_) { | 213 readyPort.handler = (_) { |
214 readyPort.close(); | 214 readyPort.close(); |
215 completer.complete(new Isolate._fromControlPort(controlPort)); | 215 completer.complete(new Isolate.fromControlPort(controlPort)); |
216 }; | 216 }; |
217 } catch(e, st) { | 217 } catch(e, st) { |
218 // TODO(floitsch): we want errors to go into the returned future. | 218 // TODO(floitsch): we want errors to go into the returned future. |
219 rethrow; | 219 rethrow; |
220 }; | 220 }; |
221 return completer.future; | 221 return completer.future; |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 patch class _Isolate { | 225 patch class _Isolate { |
226 /* patch */ static ReceivePort get port { | 226 /* patch */ static ReceivePort get port { |
227 if (_portInternal == null) { | 227 if (_portInternal == null) { |
228 _portInternal = new ReceivePort.fromRawReceivePort(_getPortInternal()); | 228 _portInternal = new ReceivePort.fromRawReceivePort(_getPortInternal()); |
229 } | 229 } |
230 return _portInternal; | 230 return _portInternal; |
231 } | 231 } |
232 | 232 |
233 static SendPort _spawnFunction(Function topLevelFunction) | 233 static SendPort _spawnFunction(Function topLevelFunction) |
234 native "isolate_spawnFunction"; | 234 native "isolate_spawnFunction"; |
235 | 235 |
236 /* patch */ static SendPort _spawnUri(String uri) native "isolate_spawnUri"; | 236 /* patch */ static SendPort _spawnUri(String uri) native "isolate_spawnUri"; |
237 } | 237 } |
OLD | NEW |