OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import '../stream_channel.dart'; | 7 import '../stream_channel.dart'; |
8 | 8 |
9 /// Allows the caller to force a channel to disconnect. | 9 /// Allows the caller to force a channel to disconnect. |
10 /// | 10 /// |
(...skipping 20 matching lines...) Expand all Loading... |
31 void disconnect() { | 31 void disconnect() { |
32 _isDisconnected = true; | 32 _isDisconnected = true; |
33 for (var sink in _sinks) { | 33 for (var sink in _sinks) { |
34 sink._disconnect(); | 34 sink._disconnect(); |
35 } | 35 } |
36 _sinks.clear(); | 36 _sinks.clear(); |
37 } | 37 } |
38 | 38 |
39 StreamChannel<T> bind(StreamChannel<T> channel) { | 39 StreamChannel<T> bind(StreamChannel<T> channel) { |
40 return channel.changeSink((innerSink) { | 40 return channel.changeSink((innerSink) { |
41 var sink = new _DisconnectorSink(innerSink); | 41 var sink = new _DisconnectorSink<T>(innerSink); |
42 | 42 |
43 if (_isDisconnected) { | 43 if (_isDisconnected) { |
44 sink._disconnect(); | 44 sink._disconnect(); |
45 } else { | 45 } else { |
46 _sinks.add(sink); | 46 _sinks.add(sink); |
47 } | 47 } |
48 | 48 |
49 return sink; | 49 return sink; |
50 }); | 50 }); |
51 } | 51 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 void _disconnect() { | 130 void _disconnect() { |
131 _isDisconnected = true; | 131 _isDisconnected = true; |
132 _inner.close(); | 132 _inner.close(); |
133 | 133 |
134 if (!_inAddStream) return; | 134 if (!_inAddStream) return; |
135 _addStreamCompleter.complete(_addStreamSubscription.cancel()); | 135 _addStreamCompleter.complete(_addStreamSubscription.cancel()); |
136 _addStreamCompleter = null; | 136 _addStreamCompleter = null; |
137 _addStreamSubscription = null; | 137 _addStreamSubscription = null; |
138 } | 138 } |
139 } | 139 } |
OLD | NEW |