Line data Source code
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 3 : // BSD-style license that can be found in the LICENSE file. 4 : 5 : import 'dart:async'; 6 : 7 : /// Simple delegating wrapper around a [StreamConsumer]. 8 : /// 9 : /// Subclasses can override individual methods, or use this to expose only the 10 : /// [StreamConsumer] methods of a subclass. 11 : class DelegatingStreamConsumer<T> implements StreamConsumer<T> { 12 : final StreamConsumer _consumer; 13 : 14 : /// Create a delegating consumer forwarding calls to [consumer]. 15 0 : DelegatingStreamConsumer(StreamConsumer<T> consumer) : _consumer = consumer; 16 : 17 0 : DelegatingStreamConsumer._(this._consumer); 18 : 19 : /// Creates a wrapper that coerces the type of [consumer]. 20 : /// 21 : /// Unlike [new StreamConsumer], this only requires its argument to be an 22 : /// instance of `StreamConsumer`, not `StreamConsumer<T>`. This means that 23 : /// calls to [addStream] may throw a [TypeError] if the argument type doesn't 24 : /// match the reified type of [consumer]. 25 0 : @Deprecated( 26 : 'Use StreamController<T>(sync: true)..stream.cast<S>().pipe(sink)') 27 : static StreamConsumer<T> typed<T>(StreamConsumer consumer) => 28 0 : consumer is StreamConsumer<T> 29 : ? consumer 30 0 : : DelegatingStreamConsumer._(consumer); 31 : 32 0 : @override 33 0 : Future addStream(Stream<T> stream) => _consumer.addStream(stream); 34 : 35 0 : @override 36 0 : Future close() => _consumer.close(); 37 : }