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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 /// Simple delegating wrapper around an [EventSink]. 7 /// Simple delegating wrapper around an [EventSink].
8 /// 8 ///
9 /// Subclasses can override individual methods, or use this to expose only the 9 /// Subclasses can override individual methods, or use this to expose only the
10 /// [EventSink] methods of a subclass. 10 /// [EventSink] methods of a subclass.
11 class DelegatingEventSink<T> implements EventSink<T> { 11 class DelegatingEventSink<T> implements EventSink<T> {
12 final EventSink _sink; 12 final EventSink _sink;
13 13
14 /// Create a delegating sink forwarding calls to [sink]. 14 /// Create a delegating sink forwarding calls to [sink].
15 DelegatingEventSink(EventSink sink) : _sink = sink; 15 DelegatingEventSink(EventSink<T> sink) : _sink = sink;
16
17 DelegatingEventSink._(this._sink);
18
19 /// Creates a wrapper that coerces the type of [sink].
20 ///
21 /// Unlike [new DelegatingEventSink], this only requires its argument to be an
22 /// instance of `EventSink`, not `EventSink<T>`. This means that calls to
23 /// [add] may throw a [CastError] if the argument type doesn't match the
24 /// reified type of [sink].
25 static EventSink/*<T>*/ typed/*<T>*/(EventSink sink) =>
26 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
16 27
17 void add(T data) { 28 void add(T data) {
18 _sink.add(data); 29 _sink.add(data);
19 } 30 }
20 31
21 void addError(error, [StackTrace stackTrace]) { 32 void addError(error, [StackTrace stackTrace]) {
22 _sink.addError(error, stackTrace); 33 _sink.addError(error, stackTrace);
23 } 34 }
24 35
25 void close() { 36 void close() {
26 _sink.close(); 37 _sink.close();
27 } 38 }
28 } 39 }
OLDNEW
« 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