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

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

Issue 1219493008: Add a bunch of delegates for dart:async types. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Created 5 years, 6 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_controller.dart
diff --git a/lib/src/delegate/stream_controller.dart b/lib/src/delegate/stream_controller.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3bcf6cb7b0a93913cb7d9fab43056a19d93ca49b
--- /dev/null
+++ b/lib/src/delegate/stream_controller.dart
@@ -0,0 +1,46 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// 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.stream_controller;
+
+import 'dart:async';
+
+import 'stream_sink.dart';
+
+/// Simple delegating wrapper around an [StreamController].
Lasse Reichstein Nielsen 2015/07/02 09:38:39 I'm not sure I'd consider StreamController an inte
nweiz 2015/07/06 20:40:30 I don't think of this as a way for otherwise non-c
Lasse Reichstein Nielsen 2015/07/07 10:32:18 I'm not sure I would encourage an extended StreamC
nweiz 2015/07/07 21:51:59 I think there's documentary value in sharing an in
+///
+/// Subclasses can override individual methods, or use this to expose only the
+/// [StreamController] methods of a subclass.
+///
+/// Note that [sink] will provide a sink view of the delegating controller,
+/// rather than of the underlying controller.
+class DelegatingStreamController<T> implements StreamController<T> {
+ final StreamController _controller;
+
+ Future get done => _controller.done;
+
+ bool get hasListener => _controller.hasListener;
+
+ bool get isClosed => _controller.isClosed;
+
+ bool get isPaused => _controller.isPaused;
+
+ StreamSink<T> get sink => new DelegatingStreamSink<T>(this);
+
+ Stream<T> get stream => _controller.stream;
+
+ /// Create a delegating controller forwarding calls to [controller].
+ DelegatingStreamController(StreamController controller)
+ : _controller = controller;
+
+ void add(T data) => _controller.add(data);
+
+ void addError(error, [StackTrace stackTrace]) =>
+ _controller.addError(error, stackTrace);
+
+ Future addStream(Stream<T> stream, {bool cancelOnError: true}) =>
+ _controller.addStream(stream, cancelOnError: cancelOnError);
+
+ Future close() => _controller.close();
+}

Powered by Google App Engine
This is Rietveld 408576698