Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: lib/src/delegate/stream_sink.dart

Issue 1870543004: Add typed wrapper functions to delegate classes. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Code review changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/src/delegate/stream_sink.dart
diff --git a/lib/src/delegate/stream_sink.dart b/lib/src/delegate/stream_sink.dart
index e06afc1b0a611c919a0d7fa6d9b69a61cecd7be7..9b52b19e5d5e642dca21e3e1b2ab812cbd8056df 100644
--- a/lib/src/delegate/stream_sink.dart
+++ b/lib/src/delegate/stream_sink.dart
@@ -14,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);

Powered by Google App Engine
This is Rietveld 408576698