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 RawReceivePort(); |
16 sendServiceMessage(sendPort, receivePort, request); | 16 sendServiceMessage(sendPort, receivePort, request); |
17 receivePort.receive((value, ignoreReplyTo) { | 17 receivePort.handler = (value) { |
18 receivePort.close(); | 18 receivePort.close(); |
19 if (value is Exception) { | 19 if (value is Exception) { |
20 completer.completeError(value); | 20 completer.completeError(value); |
21 } else { | 21 } else { |
22 completer.complete(value); | 22 completer.complete(value); |
23 } | 23 } |
24 }); | 24 }; |
25 return completer.future; | 25 return completer.future; |
26 } | 26 } |
27 | 27 |
28 Future route(ServiceRequest request) { | 28 Future route(ServiceRequest request) { |
29 // Send message to isolate. | 29 // Send message to isolate. |
30 var message = request.toServiceCallMessage(); | 30 var message = request.toServiceCallMessage(); |
31 return sendMessage(message).then((response) { | 31 return sendMessage(message).then((response) { |
32 request.setResponse(response); | 32 request.setResponse(response); |
33 return new Future.value(request); | 33 return new Future.value(request); |
34 }); | 34 }); |
35 } | 35 } |
36 } | 36 } |
OLD | NEW |