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 'package:async/async.dart'; | 7 import 'package:async/async.dart'; |
8 | 8 |
9 import 'src/guarantee_channel.dart'; | 9 import 'src/guarantee_channel.dart'; |
| 10 import 'src/close_guarantee_channel.dart'; |
10 import 'src/stream_channel_transformer.dart'; | 11 import 'src/stream_channel_transformer.dart'; |
11 | 12 |
12 export 'src/delegating_stream_channel.dart'; | 13 export 'src/delegating_stream_channel.dart'; |
13 export 'src/disconnector.dart'; | 14 export 'src/disconnector.dart'; |
14 export 'src/isolate_channel.dart'; | 15 export 'src/isolate_channel.dart'; |
15 export 'src/json_document_transformer.dart'; | 16 export 'src/json_document_transformer.dart'; |
16 export 'src/multi_channel.dart'; | 17 export 'src/multi_channel.dart'; |
17 export 'src/stream_channel_completer.dart'; | 18 export 'src/stream_channel_completer.dart'; |
18 export 'src/stream_channel_controller.dart'; | 19 export 'src/stream_channel_controller.dart'; |
19 export 'src/stream_channel_transformer.dart'; | 20 export 'src/stream_channel_transformer.dart'; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 /// just wrapping a stream and a sink directly, so [new StreamChannel] should | 81 /// just wrapping a stream and a sink directly, so [new StreamChannel] should |
81 /// be used when the guarantees are provided natively. | 82 /// be used when the guarantees are provided natively. |
82 /// | 83 /// |
83 /// If [allowSinkErrors] is `false`, errors are not allowed to be passed to | 84 /// If [allowSinkErrors] is `false`, errors are not allowed to be passed to |
84 /// [sink]. If any are, the connection will close and the error will be | 85 /// [sink]. If any are, the connection will close and the error will be |
85 /// forwarded to [Sink.done]. | 86 /// forwarded to [Sink.done]. |
86 factory StreamChannel.withGuarantees(Stream<T> stream, StreamSink<T> sink, | 87 factory StreamChannel.withGuarantees(Stream<T> stream, StreamSink<T> sink, |
87 {bool allowSinkErrors: true}) => | 88 {bool allowSinkErrors: true}) => |
88 new GuaranteeChannel(stream, sink, allowSinkErrors: allowSinkErrors); | 89 new GuaranteeChannel(stream, sink, allowSinkErrors: allowSinkErrors); |
89 | 90 |
| 91 /// Creates a new [StreamChannel] that communicates over [stream] and [sink]. |
| 92 /// |
| 93 /// This specifically enforces the second guarantee: closing the sink causes |
| 94 /// the stream to close before it emits any more events. This guarantee is |
| 95 /// invalidated when an asynchronous gap is added between the original |
| 96 /// stream's event dispatch and the returned stream's, for example by |
| 97 /// transforming it with a [StreamTransformer]. This is a lighter-weight way |
| 98 /// of preserving that guarantee in particular than |
| 99 /// [StreamChannel.withGuarantees]. |
| 100 factory StreamChannel.withCloseGuarantee(Stream<T> stream, |
| 101 StreamSink<T> sink) => |
| 102 new CloseGuaranteeChannel(stream, sink); |
| 103 |
90 /// Connects [this] to [other], so that any values emitted by either are sent | 104 /// Connects [this] to [other], so that any values emitted by either are sent |
91 /// directly to the other. | 105 /// directly to the other. |
92 void pipe(StreamChannel<T> other); | 106 void pipe(StreamChannel<T> other); |
93 | 107 |
94 /// Transforms [this] using [transformer]. | 108 /// Transforms [this] using [transformer]. |
95 /// | 109 /// |
96 /// This is identical to calling `transformer.bind(channel)`. | 110 /// This is identical to calling `transformer.bind(channel)`. |
97 StreamChannel transform(StreamChannelTransformer<T, dynamic> transformer); | 111 StreamChannel transform(StreamChannelTransformer<T, dynamic> transformer); |
98 | 112 |
99 /// Transforms only the [stream] component of [this] using [transformer]. | 113 /// Transforms only the [stream] component of [this] using [transformer]. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 StreamChannel transform(StreamChannelTransformer<T, dynamic> transformer) => | 155 StreamChannel transform(StreamChannelTransformer<T, dynamic> transformer) => |
142 transformer.bind(this); | 156 transformer.bind(this); |
143 | 157 |
144 StreamChannel<T> transformStream(StreamTransformer<T, T> transformer) => | 158 StreamChannel<T> transformStream(StreamTransformer<T, T> transformer) => |
145 changeStream(transformer.bind); | 159 changeStream(transformer.bind); |
146 | 160 |
147 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer) => | 161 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer) => |
148 changeSink(transformer.bind); | 162 changeSink(transformer.bind); |
149 | 163 |
150 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)) => | 164 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)) => |
151 new StreamChannel(change(stream), sink); | 165 new StreamChannel.withCloseGuarantee(change(stream), sink); |
152 | 166 |
153 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) => | 167 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) => |
154 new StreamChannel(stream, change(sink)); | 168 new StreamChannel.withCloseGuarantee(stream, change(sink)); |
155 | 169 |
156 StreamChannel/*<S>*/ cast/*<S>*/() => new StreamChannel( | 170 StreamChannel/*<S>*/ cast/*<S>*/() => new StreamChannel( |
157 DelegatingStream.typed(stream), DelegatingStreamSink.typed(sink)); | 171 DelegatingStream.typed(stream), DelegatingStreamSink.typed(sink)); |
158 } | 172 } |
OLD | NEW |