| 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 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 | 7 |
| 8 import 'package:async/async.dart'; | 8 import 'package:async/async.dart'; |
| 9 | 9 |
| 10 import '../stream_channel.dart'; | 10 import '../stream_channel.dart'; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 /// Creates a wrapper that coerces the type of [transformer]. | 35 /// Creates a wrapper that coerces the type of [transformer]. |
| 36 /// | 36 /// |
| 37 /// This soundly converts a [StreamChannelTransformer] to a | 37 /// This soundly converts a [StreamChannelTransformer] to a |
| 38 /// `StreamChannelTransformer<S, T>`, regardless of its original generic type, | 38 /// `StreamChannelTransformer<S, T>`, regardless of its original generic type, |
| 39 /// by asserting that the events emitted by the transformed channel's stream | 39 /// by asserting that the events emitted by the transformed channel's stream |
| 40 /// are instances of `T` whenever they're provided. If they're not, the stream | 40 /// are instances of `T` whenever they're provided. If they're not, the stream |
| 41 /// throws a [CastError]. This also means that calls to [StreamSink.add] on | 41 /// throws a [CastError]. This also means that calls to [StreamSink.add] on |
| 42 /// the transformed channel's sink may throw a [CastError] if the argument | 42 /// the transformed channel's sink may throw a [CastError] if the argument |
| 43 /// type doesn't match the reified type of the sink. | 43 /// type doesn't match the reified type of the sink. |
| 44 static StreamChannelTransformer/*<S, T>*/ typed/*<S, T>*/( | 44 static StreamChannelTransformer<S, T> typed<S, T>( |
| 45 StreamChannelTransformer transformer) => | 45 StreamChannelTransformer transformer) => |
| 46 transformer is StreamChannelTransformer/*<S, T>*/ | 46 transformer is StreamChannelTransformer<S, T> |
| 47 ? transformer | 47 ? transformer |
| 48 : new TypeSafeStreamChannelTransformer(transformer); | 48 : new TypeSafeStreamChannelTransformer(transformer); |
| 49 | 49 |
| 50 /// Creates a [StreamChannelTransformer] from existing stream and sink | 50 /// Creates a [StreamChannelTransformer] from existing stream and sink |
| 51 /// transformers. | 51 /// transformers. |
| 52 const StreamChannelTransformer( | 52 const StreamChannelTransformer( |
| 53 this._streamTransformer, this._sinkTransformer); | 53 this._streamTransformer, this._sinkTransformer); |
| 54 | 54 |
| 55 /// Creates a [StreamChannelTransformer] from a codec's encoder and decoder. | 55 /// Creates a [StreamChannelTransformer] from a codec's encoder and decoder. |
| 56 /// | 56 /// |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 /// Creates a new channel. When events are passed to the returned channel's | 67 /// Creates a new channel. When events are passed to the returned channel's |
| 68 /// sink, the transformer will transform them and pass the transformed | 68 /// sink, the transformer will transform them and pass the transformed |
| 69 /// versions to `channel.sink`. When events are emitted from the | 69 /// versions to `channel.sink`. When events are emitted from the |
| 70 /// `channel.straem`, the transformer will transform them and pass the | 70 /// `channel.straem`, the transformer will transform them and pass the |
| 71 /// transformed versions to the returned channel's stream. | 71 /// transformed versions to the returned channel's stream. |
| 72 StreamChannel<S> bind(StreamChannel<T> channel) => | 72 StreamChannel<S> bind(StreamChannel<T> channel) => |
| 73 new StreamChannel<S>.withCloseGuarantee( | 73 new StreamChannel<S>.withCloseGuarantee( |
| 74 channel.stream.transform(_streamTransformer), | 74 channel.stream.transform(_streamTransformer), |
| 75 _sinkTransformer.bind(channel.sink)); | 75 _sinkTransformer.bind(channel.sink)); |
| 76 } | 76 } |
| OLD | NEW |