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

Unified Diff: packages/async/lib/src/delegate/event_sink.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 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
« no previous file with comments | « packages/async/lib/src/cancelable_operation.dart ('k') | packages/async/lib/src/delegate/future.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « packages/async/lib/src/cancelable_operation.dart ('k') | packages/async/lib/src/delegate/future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698