Index: packages/async/lib/src/delegate/event_sink.dart |
diff --git a/packages/async/lib/src/delegate/event_sink.dart b/packages/async/lib/src/delegate/event_sink.dart |
index 337e7a811a9ddb3a2b277ffd61d8084d46d5ee69..54c3e52b65098d25ac06f48d970df78862373cde 100644 |
--- a/packages/async/lib/src/delegate/event_sink.dart |
+++ b/packages/async/lib/src/delegate/event_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.event_sink; |
- |
import 'dart:async'; |
/// Simple delegating wrapper around an [EventSink]. |
@@ -14,7 +12,18 @@ class DelegatingEventSink<T> implements EventSink<T> { |
final EventSink _sink; |
/// Create a delegating sink forwarding calls to [sink]. |
- DelegatingEventSink(EventSink sink) : _sink = sink; |
+ DelegatingEventSink(EventSink<T> sink) : _sink = sink; |
+ |
+ DelegatingEventSink._(this._sink); |
+ |
+ /// Creates a wrapper that coerces the type of [sink]. |
+ /// |
+ /// Unlike [new DelegatingEventSink], this only requires its argument to be an |
+ /// instance of `EventSink`, not `EventSink<T>`. This means that calls to |
+ /// [add] may throw a [CastError] if the argument type doesn't match the |
+ /// reified type of [sink]. |
+ static EventSink<T> typed<T>(EventSink sink) => |
+ sink is EventSink<T> ? sink : new DelegatingEventSink._(sink); |
void add(T data) { |
_sink.add(data); |