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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 /// Simple delegating wrapper around a [StreamConsumer]. | 7 /// Simple delegating wrapper around a [StreamConsumer]. |
8 /// | 8 /// |
9 /// Subclasses can override individual methods, or use this to expose only the | 9 /// Subclasses can override individual methods, or use this to expose only the |
10 /// [StreamConsumer] methods of a subclass. | 10 /// [StreamConsumer] methods of a subclass. |
11 class DelegatingStreamConsumer<T> implements StreamConsumer<T> { | 11 class DelegatingStreamConsumer<T> implements StreamConsumer<T> { |
12 final StreamConsumer _consumer; | 12 final StreamConsumer _consumer; |
13 | 13 |
14 /// Create a delegating consumer forwarding calls to [consumer]. | 14 /// Create a delegating consumer forwarding calls to [consumer]. |
15 DelegatingStreamConsumer(StreamConsumer<T> consumer) : _consumer = consumer; | 15 DelegatingStreamConsumer(StreamConsumer<T> consumer) : _consumer = consumer; |
16 | 16 |
17 DelegatingStreamConsumer._(this._consumer); | 17 DelegatingStreamConsumer._(this._consumer); |
18 | 18 |
19 /// Creates a wrapper that coerces the type of [consumer]. | 19 /// Creates a wrapper that coerces the type of [consumer]. |
20 /// | 20 /// |
21 /// Unlike [new StreamConsumer], this only requires its argument to be an | 21 /// Unlike [new StreamConsumer], this only requires its argument to be an |
22 /// instance of `StreamConsumer`, not `StreamConsumer<T>`. This means that | 22 /// instance of `StreamConsumer`, not `StreamConsumer<T>`. This means that |
23 /// calls to [addStream] may throw a [CastError] if the argument type doesn't | 23 /// calls to [addStream] may throw a [CastError] if the argument type doesn't |
24 /// match the reified type of [consumer]. | 24 /// match the reified type of [consumer]. |
25 static StreamConsumer/*<T>*/ typed/*<T>*/(StreamConsumer consumer) => | 25 static StreamConsumer<T> typed<T>(StreamConsumer consumer) => consumer |
26 consumer is StreamConsumer/*<T>*/ | 26 is StreamConsumer<T> |
nweiz
2017/01/31 22:28:58
Same here—I think the originally formatting is a l
| |
27 ? consumer | 27 ? consumer |
28 : new DelegatingStreamConsumer._(consumer); | 28 : new DelegatingStreamConsumer._(consumer); |
29 | 29 |
30 Future addStream(Stream<T> stream) => _consumer.addStream(stream); | 30 Future addStream(Stream<T> stream) => _consumer.addStream(stream); |
31 | 31 |
32 Future close() => _consumer.close(); | 32 Future close() => _consumer.close(); |
33 } | 33 } |
OLD | NEW |