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 19 matching lines...) Expand all Loading... |
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. | 35 /// Returns a [Future] that completes when the connection is closed. |
36 /// | 36 /// |
37 /// This is the same future that's returned by [listen]. | 37 /// This is the same future that's returned by [listen]. |
38 Future get done => _streams.done; | 38 Future get done => _streams.done; |
39 | 39 |
| 40 /// Whether the connection is closed. |
| 41 bool get isClosed => _streams.isClosed; |
| 42 |
40 /// Creates a [Client] that writes requests to [requests] and reads responses | 43 /// Creates a [Client] that writes requests to [requests] and reads responses |
41 /// from [responses]. | 44 /// from [responses]. |
42 /// | 45 /// |
43 /// If [responses] is a [StreamSink] as well as a [Stream] (for example, a | 46 /// If [responses] is a [StreamSink] as well as a [Stream] (for example, a |
44 /// `WebSocket`), [requests] may be omitted. | 47 /// `WebSocket`), [requests] may be omitted. |
45 /// | 48 /// |
46 /// Note that the client won't begin listening to [responses] until | 49 /// Note that the client won't begin listening to [responses] until |
47 /// [Client.listen] is called. | 50 /// [Client.listen] is called. |
48 Client(Stream<String> responses, [StreamSink<String> requests]) | 51 Client(Stream<String> responses, [StreamSink<String> requests]) |
49 : _streams = new TwoWayStream( | 52 : _streams = new TwoWayStream( |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 if (response.containsKey("result")) return true; | 194 if (response.containsKey("result")) return true; |
192 | 195 |
193 if (!response.containsKey("error")) return false; | 196 if (!response.containsKey("error")) return false; |
194 var error = response["error"]; | 197 var error = response["error"]; |
195 if (error is! Map) return false; | 198 if (error is! Map) return false; |
196 if (error["code"] is! int) return false; | 199 if (error["code"] is! int) return false; |
197 if (error["message"] is! String) return false; | 200 if (error["message"] is! String) return false; |
198 return true; | 201 return true; |
199 } | 202 } |
200 } | 203 } |
OLD | NEW |