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

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

Issue 357283003: Fix listeners being added to subscription after onListen was called. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
« no previous file with comments | « sdk/lib/async/stream_controller.dart ('k') | sdk/lib/async/stream_pipe.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/stream_impl.dart
diff --git a/sdk/lib/async/stream_impl.dart b/sdk/lib/async/stream_impl.dart
index 95691b5647f71e1b08fbfe9e12c0fb406539fb45..0133f68128c9d49de29dfbf3d31ce2cf73fe0c8b 100644
--- a/sdk/lib/async/stream_impl.dart
+++ b/sdk/lib/async/stream_impl.dart
@@ -108,8 +108,15 @@ class _BufferingStreamSubscription<T> implements StreamSubscription<T>,
*/
_PendingEvents _pending;
- _BufferingStreamSubscription(bool cancelOnError)
- : _state = (cancelOnError ? _STATE_CANCEL_ON_ERROR : 0);
+ _BufferingStreamSubscription(void onData(T data),
+ Function onError,
+ void onDone(),
+ bool cancelOnError)
+ : _state = (cancelOnError ? _STATE_CANCEL_ON_ERROR : 0) {
+ this.onData(onData);
+ this.onError(onError);
+ this.onDone(onDone);
+ }
/**
* Sets the subscription's pending events object.
@@ -466,18 +473,21 @@ abstract class _StreamImpl<T> extends Stream<T> {
void onDone(),
bool cancelOnError }) {
cancelOnError = identical(true, cancelOnError);
- StreamSubscription subscription = _createSubscription(cancelOnError);
- subscription.onData(onData);
- subscription.onError(onError);
- subscription.onDone(onDone);
+ StreamSubscription subscription =
+ _createSubscription(onData, onError, onDone, cancelOnError);
_onListen(subscription);
return subscription;
}
// -------------------------------------------------------------------
/** Create a subscription object. Called by [subcribe]. */
- _BufferingStreamSubscription<T> _createSubscription(bool cancelOnError) {
- return new _BufferingStreamSubscription<T>(cancelOnError);
+ _BufferingStreamSubscription<T> _createSubscription(
+ void onData(T data),
+ Function onError,
+ void onDone(),
+ bool cancelOnError) {
+ return new _BufferingStreamSubscription<T>(onData, onError, onDone,
+ cancelOnError);
}
/** Hook called when the subscription has been created. */
@@ -498,13 +508,15 @@ class _GeneratedStreamImpl<T> extends _StreamImpl<T> {
*/
_GeneratedStreamImpl(this._pending);
- StreamSubscription _createSubscription(bool cancelOnError) {
+ StreamSubscription _createSubscription(
+ void onData(T data),
+ Function onError,
+ void onDone(),
+ bool cancelOnError) {
if (_isUsed) throw new StateError("Stream has already been listened to.");
_isUsed = true;
- _BufferingStreamSubscription<T> subscription =
- new _BufferingStreamSubscription(cancelOnError);
- subscription._setPendingEvents(_pending());
- return subscription;
+ return new _BufferingStreamSubscription(
+ onData, onError, onDone, cancelOnError).._setPendingEvents(_pending());
}
}
@@ -824,11 +836,7 @@ class _AsBroadcastStream<T> extends Stream<T> {
onDone: _controller.close);
}
cancelOnError = identical(true, cancelOnError);
- StreamSubscription<T> result = _controller._subscribe(cancelOnError);
- result.onData(onData);
- result.onError(onError);
- result.onDone(onDone);
- return result;
+ return _controller._subscribe(onData, onError, onDone, cancelOnError);
}
void _onCancel() {
« no previous file with comments | « sdk/lib/async/stream_controller.dart ('k') | sdk/lib/async/stream_pipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698