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 an [EventSink]. 8 : /// 9 : /// Subclasses can override individual methods, or use this to expose only the 10 : /// [EventSink] methods of a subclass. 11 : class DelegatingEventSink<T> implements EventSink<T> { 12 : final EventSink _sink; 13 : 14 : /// Create a delegating sink forwarding calls to [sink]. 15 0 : DelegatingEventSink(EventSink<T> sink) : _sink = sink; 16 : 17 0 : DelegatingEventSink._(this._sink); 18 : 19 : /// Creates a wrapper that coerces the type of [sink]. 20 : /// 21 : /// Unlike [new DelegatingEventSink], this only requires its argument to be an 22 : /// instance of `EventSink`, not `EventSink<T>`. This means that calls to 23 : /// [add] may throw a [TypeError] if the argument type doesn't match the 24 : /// reified type of [sink]. 25 0 : @Deprecated( 26 : 'Use StreamController<T>(sync: true)..stream.cast<S>().pipe(sink)') 27 : static EventSink<T> typed<T>(EventSink sink) => 28 0 : sink is EventSink<T> ? sink : DelegatingEventSink._(sink); 29 : 30 0 : @override 31 : void add(T data) { 32 0 : _sink.add(data); 33 : } 34 : 35 0 : @override 36 : void addError(error, [StackTrace? stackTrace]) { 37 0 : _sink.addError(error, stackTrace); 38 : } 39 : 40 0 : @override 41 : void close() { 42 0 : _sink.close(); 43 : } 44 : }