| 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/stream_channel_transformer.dart'; | 10 import 'src/stream_channel_transformer.dart'; |
| 10 | 11 |
| 11 export 'src/delegating_stream_channel.dart'; | 12 export 'src/delegating_stream_channel.dart'; |
| 12 export 'src/isolate_channel.dart'; | 13 export 'src/isolate_channel.dart'; |
| 13 export 'src/json_document_transformer.dart'; | 14 export 'src/json_document_transformer.dart'; |
| 14 export 'src/multi_channel.dart'; | 15 export 'src/multi_channel.dart'; |
| 15 export 'src/stream_channel_completer.dart'; | 16 export 'src/stream_channel_completer.dart'; |
| 17 export 'src/stream_channel_controller.dart'; |
| 16 export 'src/stream_channel_transformer.dart'; | 18 export 'src/stream_channel_transformer.dart'; |
| 17 | 19 |
| 18 /// An abstract class representing a two-way communication channel. | 20 /// An abstract class representing a two-way communication channel. |
| 19 /// | 21 /// |
| 20 /// Users should consider the [stream] emitting a "done" event to be the | 22 /// Users should consider the [stream] emitting a "done" event to be the |
| 21 /// canonical indicator that the channel has closed. If they wish to close the | 23 /// canonical indicator that the channel has closed. If they wish to close the |
| 22 /// channel, they should close the [sink]—canceling the stream subscription is | 24 /// channel, they should close the [sink]—canceling the stream subscription is |
| 23 /// not sufficient. Protocol errors may be emitted through the stream or through | 25 /// not sufficient. Protocol errors may be emitted through the stream or through |
| 24 /// [Sink.done], depending on their underlying cause. Note that the sink may | 26 /// [Sink.done], depending on their underlying cause. Note that the sink may |
| 25 /// silently drop events if the channel closes before [Sink.close] is called. | 27 /// silently drop events if the channel closes before [Sink.close] is called. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 abstract class StreamChannel<T> { | 60 abstract class StreamChannel<T> { |
| 59 /// The single-subscription stream that emits values from the other endpoint. | 61 /// The single-subscription stream that emits values from the other endpoint. |
| 60 Stream<T> get stream; | 62 Stream<T> get stream; |
| 61 | 63 |
| 62 /// The sink for sending values to the other endpoint. | 64 /// The sink for sending values to the other endpoint. |
| 63 StreamSink<T> get sink; | 65 StreamSink<T> get sink; |
| 64 | 66 |
| 65 /// Creates a new [StreamChannel] that communicates over [stream] and [sink]. | 67 /// Creates a new [StreamChannel] that communicates over [stream] and [sink]. |
| 66 /// | 68 /// |
| 67 /// Note that this stream/sink pair must provide the guarantees listed in the | 69 /// Note that this stream/sink pair must provide the guarantees listed in the |
| 68 /// [StreamChannel] documentation. | 70 /// [StreamChannel] documentation. If they don't do so natively, [new |
| 71 /// StreamChannel.withGuarantees] should be used instead. |
| 69 factory StreamChannel(Stream<T> stream, StreamSink<T> sink) => | 72 factory StreamChannel(Stream<T> stream, StreamSink<T> sink) => |
| 70 new _StreamChannel<T>(stream, sink); | 73 new _StreamChannel<T>(stream, sink); |
| 71 | 74 |
| 75 /// Creates a new [StreamChannel] that communicates over [stream] and [sink]. |
| 76 /// |
| 77 /// Unlike [new StreamChannel], this enforces the guarantees listed in the |
| 78 /// [StreamChannel] documentation. This makes it somewhat less efficient than |
| 79 /// just wrapping a stream and a sink directly, so [new StreamChannel] should |
| 80 /// be used when the guarantees are provided natively. |
| 81 factory StreamChannel.withGuarantees(Stream<T> stream, StreamSink<T> sink) => |
| 82 new GuaranteeChannel(stream, sink); |
| 83 |
| 72 /// Connects [this] to [other], so that any values emitted by either are sent | 84 /// Connects [this] to [other], so that any values emitted by either are sent |
| 73 /// directly to the other. | 85 /// directly to the other. |
| 74 void pipe(StreamChannel<T> other); | 86 void pipe(StreamChannel<T> other); |
| 75 | 87 |
| 76 /// Transforms [this] using [transformer]. | 88 /// Transforms [this] using [transformer]. |
| 77 /// | 89 /// |
| 78 /// This is identical to calling `transformer.bind(channel)`. | 90 /// This is identical to calling `transformer.bind(channel)`. |
| 79 StreamChannel transform(StreamChannelTransformer<T, dynamic> transformer); | 91 StreamChannel transform(StreamChannelTransformer<T, dynamic> transformer); |
| 80 | 92 |
| 81 /// Transforms only the [stream] component of [this] using [transformer]. | 93 /// Transforms only the [stream] component of [this] using [transformer]. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 133 |
| 122 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer) => | 134 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer) => |
| 123 changeSink(transformer.bind); | 135 changeSink(transformer.bind); |
| 124 | 136 |
| 125 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)) => | 137 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)) => |
| 126 new StreamChannel(change(stream), sink); | 138 new StreamChannel(change(stream), sink); |
| 127 | 139 |
| 128 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) => | 140 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) => |
| 129 new StreamChannel(stream, change(sink)); | 141 new StreamChannel(stream, change(sink)); |
| 130 } | 142 } |
| OLD | NEW |