Index: packages/async/lib/src/delegate/stream_sink.dart |
diff --git a/packages/async/lib/src/delegate/stream_sink.dart b/packages/async/lib/src/delegate/stream_sink.dart |
index b6ace650cb14c3d70a7ce711d8f1d890312c4d30..198df8a785dcfae6c0adf4c58194899505013a40 100644 |
--- a/packages/async/lib/src/delegate/stream_sink.dart |
+++ b/packages/async/lib/src/delegate/stream_sink.dart |
@@ -2,8 +2,6 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-library async.delegate.stream_sink; |
- |
import 'dart:async'; |
/// Simple delegating wrapper around a [StreamSink]. |
@@ -16,8 +14,18 @@ class DelegatingStreamSink<T> implements StreamSink<T> { |
Future get done => _sink.done; |
/// Create delegating sink forwarding calls to [sink]. |
- DelegatingStreamSink(StreamSink sink) |
- : _sink = sink; |
+ DelegatingStreamSink(StreamSink<T> sink) : _sink = sink; |
+ |
+ DelegatingStreamSink._(this._sink); |
+ |
+ /// Creates a wrapper that coerces the type of [sink]. |
+ /// |
+ /// Unlike [new StreamSink], this only requires its argument to be an instance |
+ /// of `StreamSink`, not `StreamSink<T>`. This means that calls to [add] may |
+ /// throw a [CastError] if the argument type doesn't match the reified type of |
+ /// [sink]. |
+ static StreamSink<T> typed<T>(StreamSink sink) => |
+ sink is StreamSink<T> ? sink : new DelegatingStreamSink._(sink); |
void add(T data) { |
_sink.add(data); |