| 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.peer; | 5 library json_rpc_2.peer; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../error_code.dart' as error_code; | 9 import '../error_code.dart' as error_code; |
| 10 import 'client.dart'; | 10 import 'client.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 /// A stream controller that forwards incoming messages to [_client] if | 36 /// A stream controller that forwards incoming messages to [_client] if |
| 37 /// they're responses. | 37 /// they're responses. |
| 38 final _clientIncomingForwarder = new StreamController(sync: true); | 38 final _clientIncomingForwarder = new StreamController(sync: true); |
| 39 | 39 |
| 40 /// A stream controller that forwards outgoing messages from both [_server] | 40 /// A stream controller that forwards outgoing messages from both [_server] |
| 41 /// and [_client]. | 41 /// and [_client]. |
| 42 final _outgoingForwarder = new StreamController(sync: true); | 42 final _outgoingForwarder = new StreamController(sync: true); |
| 43 | 43 |
| 44 Future get done => _streams.done; | 44 Future get done => _streams.done; |
| 45 bool get isClosed => _streams.isClosed; |
| 45 | 46 |
| 46 /// Creates a [Peer] that reads incoming messages from [incoming] and writes | 47 /// Creates a [Peer] that reads incoming messages from [incoming] and writes |
| 47 /// outgoing messages to [outgoing]. | 48 /// outgoing messages to [outgoing]. |
| 48 /// | 49 /// |
| 49 /// If [incoming] is a [StreamSink] as well as a [Stream] (for example, a | 50 /// If [incoming] is a [StreamSink] as well as a [Stream] (for example, a |
| 50 /// `WebSocket`), [outgoing] may be omitted. | 51 /// `WebSocket`), [outgoing] may be omitted. |
| 51 /// | 52 /// |
| 52 /// Note that the peer won't begin listening to [incoming] until [Peer.listen] | 53 /// Note that the peer won't begin listening to [incoming] until [Peer.listen] |
| 53 /// is called. | 54 /// is called. |
| 54 Peer(Stream<String> incoming, [StreamSink<String> outgoing]) { | 55 Peer(Stream<String> incoming, [StreamSink<String> outgoing]) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // Non-Map and -List messages are ill-formed, so we pass them to the | 130 // Non-Map and -List messages are ill-formed, so we pass them to the |
| 130 // server since it knows how to send error responses. | 131 // server since it knows how to send error responses. |
| 131 _serverIncomingForwarder.add(message); | 132 _serverIncomingForwarder.add(message); |
| 132 } | 133 } |
| 133 }); | 134 }); |
| 134 } | 135 } |
| 135 | 136 |
| 136 Future close() => | 137 Future close() => |
| 137 Future.wait([_client.close(), _server.close(), _streams.close()]); | 138 Future.wait([_client.close(), _server.close(), _streams.close()]); |
| 138 } | 139 } |
| OLD | NEW |