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

Unified Diff: lib/src/delegate/event_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/event_sink.dart
diff --git a/lib/src/delegate/event_sink.dart b/lib/src/delegate/event_sink.dart
index 5a525dfc8c55d079a21ef7f4e0c0366134a9889a..14501b28d3ea65906c4cf3ebd51cf5a5c61e74ac 100644
--- a/lib/src/delegate/event_sink.dart
+++ b/lib/src/delegate/event_sink.dart
@@ -12,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);
floitsch 2016/04/12 20:03:07 new DelegatingEventSink<T>
nweiz 2016/04/12 20:41:19 This is inferred from the return type.
floitsch 2016/04/14 13:59:45 Maybe, but that's non-intuitive, and it shouldn't
nweiz 2016/04/14 19:27:16 I think it's pretty intuitive. It's right there in
void add(T data) {
_sink.add(data);
« no previous file with comments | « lib/async.dart ('k') | lib/src/delegate/future.dart » ('j') | lib/src/delegate/future.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698