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

Unified Diff: sdk/lib/async/stream_controller.dart

Issue 1242023007: Add setters for callbacks on StreamController. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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 | « sdk/lib/async/broadcast_stream_controller.dart ('k') | tests/lib/async/stream_controller_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/stream_controller.dart
diff --git a/sdk/lib/async/stream_controller.dart b/sdk/lib/async/stream_controller.dart
index 5764ecdd2102e6dc975a6c1ca3d81a0ed4db3ad4..26dc882b5a5d1562ee91aaa14977018778f25aef 100644
--- a/sdk/lib/async/stream_controller.dart
+++ b/sdk/lib/async/stream_controller.dart
@@ -77,12 +77,6 @@ abstract class StreamController<T> implements StreamSink<T> {
void onResume(),
onCancel(),
bool sync: false}) {
- if (onListen == null && onPause == null &&
- onResume == null && onCancel == null) {
- return sync
- ? new _NoCallbackSyncStreamController<T>()
- : new _NoCallbackAsyncStreamController<T>();
- }
return sync
? new _SyncStreamController<T>(onListen, onPause, onResume, onCancel)
: new _AsyncStreamController<T>(onListen, onPause, onResume, onCancel);
@@ -139,6 +133,42 @@ abstract class StreamController<T> implements StreamSink<T> {
}
/**
+ * Set the callback which is called when the stream is listened to.
floitsch 2015/07/17 09:47:52 Sets
+ *
+ * This overrides the previous callback, or clears it if the handler is
+ * `null`.
+ */
+ void set onListen(void onListenHandler());
+
+ /**
+ * Set the callback which is called when the stream is paused.
floitsch 2015/07/17 09:47:53 ditto. and for the others.
+ *
+ * This overrides the previous callback, or clears it if the handler is
+ * `null`.
+ *
+ * Pause related callbacks are not supported on broadcast stream controllers.
+ */
+ void set onPause(void onPauseHandler());
+
+ /**
+ * Set the callback which is called when the stream is resumed.
+ *
+ * This overrides the previous callback, or clears it if the handler is
+ * `null`.
+ *
+ * Pause related callbacks are not supported on broadcast stream controllers.
+ */
+ void set onResume(void onResumeHandler());
+
+ /**
+ * Set the callback which is called when the stream is canceled.
+ *
+ * This overrides the previous callback, or clears it if the handler is
+ * `null`.
+ */
+ void set onCancel(onCancelHandler());
+
+ /**
* Returns a view of this object that only exposes the [StreamSink] interface.
*/
StreamSink<T> get sink;
@@ -383,12 +413,23 @@ abstract class _StreamController<T> implements StreamController<T>,
// accessed earlier, or if close is called before subscribing.
_Future _doneFuture;
- _StreamController();
+ _NotificationHandler _onListen;
+ _NotificationHandler _onPause;
+ _NotificationHandler _onResume;
+ _NotificationHandler _onCancel;
- _NotificationHandler get _onListen;
- _NotificationHandler get _onPause;
- _NotificationHandler get _onResume;
- _NotificationHandler get _onCancel;
+ _StreamController(void this._onListen(),
+ void this._onPause(),
+ void this._onResume(),
+ this._onCancel());
+
+ void set onListen(void onListenHandler()) { _onListen = onListenHandler; }
+
+ void set onPause(void onPauseHandler()) { _onPause = onPauseHandler; }
+
+ void set onResume(void onResumeHandler()) { _onResume = onResumeHandler; }
+
+ void set onCancel(onCancelHandler()) { _onCancel = onCancelHandler; }
// Return a new stream every time. The streams are equal, but not identical.
Stream<T> get stream => new _ControllerStream<T>(this);
@@ -722,44 +763,11 @@ abstract class _AsyncStreamControllerDispatch<T>
// TODO(lrn): Use common superclass for callback-controllers when VM supports
// constructors in mixin superclasses.
-class _AsyncStreamController<T> extends _StreamController<T>
- with _AsyncStreamControllerDispatch<T> {
- final _NotificationHandler _onListen;
- final _NotificationHandler _onPause;
- final _NotificationHandler _onResume;
- final _NotificationHandler _onCancel;
+class _AsyncStreamController<T> = _StreamController<T>
+ with _AsyncStreamControllerDispatch<T>;
- _AsyncStreamController(void this._onListen(),
- void this._onPause(),
- void this._onResume(),
- this._onCancel());
-}
-
-class _SyncStreamController<T> extends _StreamController<T>
- with _SyncStreamControllerDispatch<T> {
- final _NotificationHandler _onListen;
- final _NotificationHandler _onPause;
- final _NotificationHandler _onResume;
- final _NotificationHandler _onCancel;
-
- _SyncStreamController(void this._onListen(),
- void this._onPause(),
- void this._onResume(),
- this._onCancel());
-}
-
-abstract class _NoCallbacks {
- _NotificationHandler get _onListen => null;
- _NotificationHandler get _onPause => null;
- _NotificationHandler get _onResume => null;
- _NotificationHandler get _onCancel => null;
-}
-
-class _NoCallbackAsyncStreamController<T> = _StreamController<T>
- with _AsyncStreamControllerDispatch<T>, _NoCallbacks;
-
-class _NoCallbackSyncStreamController<T> = _StreamController<T>
- with _SyncStreamControllerDispatch<T>, _NoCallbacks;
+class _SyncStreamController<T> = _StreamController<T>
+ with _SyncStreamControllerDispatch<T>;
typedef _NotificationHandler();
« no previous file with comments | « sdk/lib/async/broadcast_stream_controller.dart ('k') | tests/lib/async/stream_controller_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698