Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 } | 33 } |
| 34 | 34 |
| 35 SendPort get sendPort { | 35 SendPort get sendPort { |
| 36 return _rawPort.sendPort; | 36 return _rawPort.sendPort; |
| 37 } | 37 } |
| 38 | 38 |
| 39 StreamSubscription listen(void onData(var message), | 39 StreamSubscription listen(void onData(var message), |
| 40 { Function onError, | 40 { Function onError, |
| 41 void onDone(), | 41 void onDone(), |
| 42 bool cancelOnError }) { | 42 bool cancelOnError }) { |
| 43 return _controller.stream.listen(onData); | 43 return _controller.stream.listen(onData, |
| 44 onError: onError, | |
| 45 onDone: onDone, | |
| 46 cancelOnError: cancelOnError); | |
| 44 } | 47 } |
| 45 | 48 |
| 46 close() { | 49 close() { |
| 47 _rawPort.close(); | 50 _rawPort.close(); |
| 48 _controller.close(); | 51 _controller.close(); |
| 49 } | 52 } |
| 50 | 53 |
| 51 final RawReceivePort _rawPort; | 54 final RawReceivePort _rawPort; |
| 52 StreamController _controller; | 55 StreamController _controller; |
| 53 } | 56 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 // TODO(floitsch): we want errors to go into the returned future. | 205 // TODO(floitsch): we want errors to go into the returned future. |
| 203 rethrow; | 206 rethrow; |
| 204 }; | 207 }; |
| 205 return completer.future; | 208 return completer.future; |
| 206 } | 209 } |
| 207 | 210 |
| 208 /* patch */ static Future<Isolate> spawnUri( | 211 /* patch */ static Future<Isolate> spawnUri( |
| 209 Uri uri, List<String> args, var message) { | 212 Uri uri, List<String> args, var message) { |
| 210 Completer completer = new Completer<Isolate>.sync(); | 213 Completer completer = new Completer<Isolate>.sync(); |
| 211 try { | 214 try { |
| 215 if (args is List<String>) { | |
| 216 for (int i = 0; i < args.length; i++) { | |
| 217 if (args[i] is! String) { | |
| 218 throw new ArgumentError("Args must be a list of Strings $args"); | |
| 219 } | |
| 220 } | |
| 221 } else if (args != null) { | |
| 222 throw new ArgumentError("Args must be a list of Strings $args"); | |
|
Lasse Reichstein Nielsen
2013/10/25 14:28:24
If we allow null, will it be null at the other end
floitsch
2013/10/25 14:33:14
I would say `null`.
| |
| 223 } | |
| 212 // The VM will invoke [_startIsolate] and not `main`. | 224 // The VM will invoke [_startIsolate] and not `main`. |
| 213 SendPort controlPort = _spawnUri(uri.path); | 225 SendPort controlPort = _spawnUri(uri.path); |
| 214 RawReceivePort readyPort = new RawReceivePort(); | 226 RawReceivePort readyPort = new RawReceivePort(); |
| 215 controlPort.send([readyPort.sendPort, args, message]); | 227 controlPort.send([readyPort.sendPort, args, message]); |
| 216 readyPort.handler = (readyMessage) { | 228 readyPort.handler = (readyMessage) { |
| 217 assert(readyMessage == 'started'); | 229 assert(readyMessage == 'started'); |
| 218 readyPort.close(); | 230 readyPort.close(); |
| 219 completer.complete(new Isolate._fromControlPort(controlPort)); | 231 completer.complete(new Isolate._fromControlPort(controlPort)); |
| 220 }; | 232 }; |
| 221 } catch(e, st) { | 233 } catch(e, st) { |
| 222 // TODO(floitsch): we want errors to go into the returned future. | 234 // TODO(floitsch): we want errors to go into the returned future. |
| 223 rethrow; | 235 rethrow; |
| 224 }; | 236 }; |
| 225 return completer.future; | 237 return completer.future; |
| 226 } | 238 } |
| 227 | 239 |
| 228 static final ReceivePort _port = | 240 static final ReceivePort _port = |
| 229 new ReceivePort.fromRawReceivePort(_getPortInternal()); | 241 new ReceivePort.fromRawReceivePort(_getPortInternal()); |
| 230 | 242 |
| 231 static SendPort _spawnFunction(Function topLevelFunction) | 243 static SendPort _spawnFunction(Function topLevelFunction) |
| 232 native "isolate_spawnFunction"; | 244 native "isolate_spawnFunction"; |
| 233 | 245 |
| 234 static SendPort _spawnUri(String uri) native "isolate_spawnUri"; | 246 static SendPort _spawnUri(String uri) native "isolate_spawnUri"; |
| 235 } | 247 } |
| OLD | NEW |