OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #library("proxy"); | 5 #library("proxy"); |
6 #import("dart:isolate"); | 6 #import("dart:isolate"); |
7 | 7 |
8 /** | 8 /** |
9 * Base class for all RpcProxy's | 9 * Base class for all RpcProxy's |
10 * | 10 * |
(...skipping 17 matching lines...) Expand all Loading... |
28 * isolate). | 28 * isolate). |
29 * | 29 * |
30 * returns: | 30 * returns: |
31 * a Future object that will be set to the value that was | 31 * a Future object that will be set to the value that was |
32 * received as a reply to the SendPort call. | 32 * received as a reply to the SendPort call. |
33 */ | 33 */ |
34 Future sendCommand(String command, List args, adjustReply(Object value)) { | 34 Future sendCommand(String command, List args, adjustReply(Object value)) { |
35 Completer completer = new Completer(); | 35 Completer completer = new Completer(); |
36 futurePort.then((SendPort port) { | 36 futurePort.then((SendPort port) { |
37 args = _filterArgs(args); | 37 args = _filterArgs(args); |
38 port.call({"command" : command, "args" : args}).receive( | 38 port.call({"command" : command, "args" : args}).then((value) { |
39 (value, ignoreReplyTo) { | |
40 assert(ignoreReplyTo === null); | |
41 value = _filterException(value); | 39 value = _filterException(value); |
42 if (adjustReply != null) { | 40 if (adjustReply != null) { |
43 // give derived proxy class a chance to transate SendPort to | 41 // give derived proxy class a chance to transate SendPort to |
44 // RpcProxy | 42 // RpcProxy |
45 value = adjustReply(value); | 43 value = adjustReply(value); |
46 } | 44 } |
47 if (value is Exception) { | 45 if (value is Exception) { |
48 completer.completeException(value); | 46 completer.completeException(value); |
49 } else { | 47 } else { |
50 completer.complete(value); | 48 completer.complete(value); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 if (object === null || !(object is String)) { | 229 if (object === null || !(object is String)) { |
232 return null; | 230 return null; |
233 } | 231 } |
234 String s = object; | 232 String s = object; |
235 if (!s.startsWith(prefix)) { | 233 if (!s.startsWith(prefix)) { |
236 return null; | 234 return null; |
237 } | 235 } |
238 return new RpcException(s.substring(prefix.length, s.length)); | 236 return new RpcException(s.substring(prefix.length, s.length)); |
239 } | 237 } |
240 } | 238 } |
OLD | NEW |