OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 json_rpc_2.client; | 5 library json_rpc_2.client; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 /// The current batch of requests to be sent together. | 26 /// The current batch of requests to be sent together. |
27 /// | 27 /// |
28 /// Each element is a JSON-serializable object. | 28 /// Each element is a JSON-serializable object. |
29 List _batch; | 29 List _batch; |
30 | 30 |
31 /// The map of request ids for pending requests to [Completer]s that will be | 31 /// The map of request ids for pending requests to [Completer]s that will be |
32 /// completed with those requests' responses. | 32 /// completed with those requests' responses. |
33 final _pendingRequests = new Map<int, Completer>(); | 33 final _pendingRequests = new Map<int, Completer>(); |
34 | 34 |
| 35 /// Returns a [Future] that completes when the connection is closed. |
| 36 /// |
| 37 /// This is the same future that's returned by [listen]. |
| 38 Future get done => _streams.done; |
| 39 |
35 /// Creates a [Client] that writes requests to [requests] and reads responses | 40 /// Creates a [Client] that writes requests to [requests] and reads responses |
36 /// from [responses]. | 41 /// from [responses]. |
37 /// | 42 /// |
38 /// If [responses] is a [StreamSink] as well as a [Stream] (for example, a | 43 /// If [responses] is a [StreamSink] as well as a [Stream] (for example, a |
39 /// `WebSocket`), [requests] may be omitted. | 44 /// `WebSocket`), [requests] may be omitted. |
40 /// | 45 /// |
41 /// Note that the client won't begin listening to [responses] until | 46 /// Note that the client won't begin listening to [responses] until |
42 /// [Client.listen] is called. | 47 /// [Client.listen] is called. |
43 Client(Stream<String> responses, [StreamSink<String> requests]) | 48 Client(Stream<String> responses, [StreamSink<String> requests]) |
44 : _streams = new TwoWayStream( | 49 : _streams = new TwoWayStream( |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (response.containsKey("result")) return true; | 191 if (response.containsKey("result")) return true; |
187 | 192 |
188 if (!response.containsKey("error")) return false; | 193 if (!response.containsKey("error")) return false; |
189 var error = response["error"]; | 194 var error = response["error"]; |
190 if (error is! Map) return false; | 195 if (error is! Map) return false; |
191 if (error["code"] is! int) return false; | 196 if (error["code"] is! int) return false; |
192 if (error["message"] is! String) return false; | 197 if (error["message"] is! String) return false; |
193 return true; | 198 return true; |
194 } | 199 } |
195 } | 200 } |
OLD | NEW |