| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 vmservice; | 5 part of vmservice; |
| 6 | 6 |
| 7 class RunningIsolate implements ServiceRequestRouter { | 7 class RunningIsolate implements ServiceRequestRouter { |
| 8 final SendPort sendPort; | 8 final SendPort sendPort; |
| 9 final String name; | 9 final String name; |
| 10 | 10 |
| 11 RunningIsolate(this.sendPort, this.name); | 11 RunningIsolate(this.sendPort, this.name); |
| 12 | 12 |
| 13 Future sendMessage(List request) { | 13 Future sendMessage(List request) { |
| 14 final completer = new Completer.sync(); | 14 final completer = new Completer.sync(); |
| 15 final receivePort = new ReceivePort(); | 15 final receivePort = new ReceivePort(); |
| 16 sendServiceMessage(sendPort, receivePort, request); | 16 sendServiceMessage(sendPort, receivePort, request); |
| 17 receivePort.receive((value, ignoreReplyTo) { | 17 receivePort.first.then((value) { |
| 18 receivePort.close(); | |
| 19 if (value is Exception) { | 18 if (value is Exception) { |
| 20 completer.completeError(value); | 19 completer.completeError(value); |
| 21 } else { | 20 } else { |
| 22 completer.complete(value); | 21 completer.complete(value); |
| 23 } | 22 } |
| 24 }); | 23 }); |
| 25 return completer.future; | 24 return completer.future; |
| 26 } | 25 } |
| 27 | 26 |
| 28 Future route(ServiceRequest request) { | 27 Future route(ServiceRequest request) { |
| 29 // Send message to isolate. | 28 // Send message to isolate. |
| 30 var message = request.toServiceCallMessage(); | 29 var message = request.toServiceCallMessage(); |
| 31 return sendMessage(message).then((response) { | 30 return sendMessage(message).then((response) { |
| 32 request.setResponse(response); | 31 request.setResponse(response); |
| 33 return new Future.value(request); | 32 return new Future.value(request); |
| 34 }); | 33 }); |
| 35 } | 34 } |
| 36 } | 35 } |
| OLD | NEW |