| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 test.multi_channel; | 5 library test.multi_channel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'stream_channel.dart'; | 9 import 'stream_channel.dart'; |
| 10 | 10 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 onDone: () => _closeChannel(inputId, outputId)); | 195 onDone: () => _closeChannel(inputId, outputId)); |
| 196 | 196 |
| 197 return new VirtualChannel._( | 197 return new VirtualChannel._( |
| 198 this, outputId, streamController.stream, sinkController.sink); | 198 this, outputId, streamController.stream, sinkController.sink); |
| 199 } | 199 } |
| 200 | 200 |
| 201 /// Closes the virtual channel for which incoming messages have [inputId] and | 201 /// Closes the virtual channel for which incoming messages have [inputId] and |
| 202 /// outgoing messages have [outputId]. | 202 /// outgoing messages have [outputId]. |
| 203 void _closeChannel(int inputId, int outputId) { | 203 void _closeChannel(int inputId, int outputId) { |
| 204 if (_closed) return; | 204 if (_closed) return; |
| 205 _closed = true; | 205 _closed = inputId == 0; |
| 206 | 206 |
| 207 // A message without data indicates that the virtual channel has been | 207 // A message without data indicates that the virtual channel has been |
| 208 // closed. | 208 // closed. |
| 209 _streamControllers.remove(inputId).close(); | 209 _streamControllers.remove(inputId).close(); |
| 210 _sinkControllers.remove(inputId).close(); | 210 _sinkControllers.remove(inputId).close(); |
| 211 | 211 |
| 212 if (_innerSink == null) return; | 212 if (_innerSink == null) return; |
| 213 _innerSink.add([outputId]); | 213 _innerSink.add([outputId]); |
| 214 if (_streamControllers.isEmpty) _closeInnerChannel(); | 214 if (_streamControllers.isEmpty) _closeInnerChannel(); |
| 215 } | 215 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 242 /// except that it will be JSON-serializable. | 242 /// except that it will be JSON-serializable. |
| 243 final id; | 243 final id; |
| 244 | 244 |
| 245 final Stream stream; | 245 final Stream stream; |
| 246 final StreamSink sink; | 246 final StreamSink sink; |
| 247 | 247 |
| 248 VirtualChannel._(this._parent, this.id, this.stream, this.sink); | 248 VirtualChannel._(this._parent, this.id, this.stream, this.sink); |
| 249 | 249 |
| 250 VirtualChannel virtualChannel([id]) => _parent.virtualChannel(id); | 250 VirtualChannel virtualChannel([id]) => _parent.virtualChannel(id); |
| 251 } | 251 } |
| OLD | NEW |