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 import "dart:collection" show HashMap; | 5 import "dart:collection" show HashMap; |
6 | 6 |
7 patch class ReceivePort { | 7 patch class ReceivePort { |
8 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
9 | 9 |
10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = | 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 // The VM will invoke [_startIsolate] with entryPoint as argument. | 234 // The VM will invoke [_startIsolate] with entryPoint as argument. |
235 SendPort controlPort = _spawnFunction(entryPoint); | 235 SendPort controlPort = _spawnFunction(entryPoint); |
236 RawReceivePort readyPort = new RawReceivePort(); | 236 RawReceivePort readyPort = new RawReceivePort(); |
237 controlPort.send([readyPort.sendPort, message]); | 237 controlPort.send([readyPort.sendPort, message]); |
238 readyPort.handler = (readyMessage) { | 238 readyPort.handler = (readyMessage) { |
239 assert(readyMessage == 'started'); | 239 assert(readyMessage == 'started'); |
240 readyPort.close(); | 240 readyPort.close(); |
241 completer.complete(new Isolate._fromControlPort(controlPort)); | 241 completer.complete(new Isolate._fromControlPort(controlPort)); |
242 }; | 242 }; |
243 } catch(e, st) { | 243 } catch(e, st) { |
244 // TODO(14718): we want errors to go into the returned future. | 244 // Don't complete immediately with an error, since the caller didn't |
245 rethrow; | 245 // yet have the time to install an error handler. |
Ivan Posva
2013/12/12 12:11:49
time -> opportunity
floitsch
2013/12/12 21:08:37
Done.
| |
246 scheduleMicrotask(() { | |
247 completer.completeError(e, st); | |
248 }); | |
246 }; | 249 }; |
247 return completer.future; | 250 return completer.future; |
248 } | 251 } |
249 | 252 |
250 /* patch */ static Future<Isolate> spawnUri( | 253 /* patch */ static Future<Isolate> spawnUri( |
251 Uri uri, List<String> args, var message) { | 254 Uri uri, List<String> args, var message) { |
252 Completer completer = new Completer<Isolate>.sync(); | 255 Completer completer = new Completer<Isolate>.sync(); |
253 try { | 256 try { |
254 // The VM will invoke [_startIsolate] and not `main`. | 257 // The VM will invoke [_startIsolate] and not `main`. |
255 SendPort controlPort = _spawnUri(uri.toString()); | 258 SendPort controlPort = _spawnUri(uri.toString()); |
256 RawReceivePort readyPort = new RawReceivePort(); | 259 RawReceivePort readyPort = new RawReceivePort(); |
257 controlPort.send([readyPort.sendPort, args, message]); | 260 controlPort.send([readyPort.sendPort, args, message]); |
258 readyPort.handler = (readyMessage) { | 261 readyPort.handler = (readyMessage) { |
259 assert(readyMessage == 'started'); | 262 assert(readyMessage == 'started'); |
260 readyPort.close(); | 263 readyPort.close(); |
261 completer.complete(new Isolate._fromControlPort(controlPort)); | 264 completer.complete(new Isolate._fromControlPort(controlPort)); |
262 }; | 265 }; |
263 } catch(e, st) { | 266 } catch(e, st) { |
264 // TODO(14718): we want errors to go into the returned future. | 267 // Don't complete immediately with an error, since the caller didn't |
265 rethrow; | 268 // yet have the time to install an error handler. |
Ivan Posva
2013/12/12 12:11:49
ditto
floitsch
2013/12/12 21:08:37
Done.
| |
269 scheduleMicrotask(() { | |
270 completer.completeError(e, st); | |
271 }); | |
266 }; | 272 }; |
267 return completer.future; | 273 return completer.future; |
268 } | 274 } |
269 | 275 |
270 static final RawReceivePort _self = _mainPort; | 276 static final RawReceivePort _self = _mainPort; |
271 static RawReceivePort get _mainPort native "Isolate_mainPort"; | 277 static RawReceivePort get _mainPort native "Isolate_mainPort"; |
272 | 278 |
273 static SendPort _spawnFunction(Function topLevelFunction) | 279 static SendPort _spawnFunction(Function topLevelFunction) |
274 native "Isolate_spawnFunction"; | 280 native "Isolate_spawnFunction"; |
275 | 281 |
276 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; | 282 static SendPort _spawnUri(String uri) native "Isolate_spawnUri"; |
277 } | 283 } |
OLD | NEW |