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

Side by Side Diff: sdk/lib/async/stream_pipe.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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | sdk/lib/async/stream_transformers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart.async; 5 part of dart.async;
6 6
7 /** Runs user code and takes actions depending on success or failure. */ 7 /** Runs user code and takes actions depending on success or failure. */
8 _runUserCode(userCode(), 8 _runUserCode(userCode(),
9 onSuccess(value), 9 onSuccess(value),
10 onError(error, StackTrace stackTrace)) { 10 onError(error, StackTrace stackTrace)) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 _ForwardingStream(this._source); 61 _ForwardingStream(this._source);
62 62
63 bool get isBroadcast => _source.isBroadcast; 63 bool get isBroadcast => _source.isBroadcast;
64 64
65 StreamSubscription<T> listen(void onData(T value), 65 StreamSubscription<T> listen(void onData(T value),
66 { Function onError, 66 { Function onError,
67 void onDone(), 67 void onDone(),
68 bool cancelOnError }) { 68 bool cancelOnError }) {
69 cancelOnError = identical(true, cancelOnError); 69 cancelOnError = identical(true, cancelOnError);
70 StreamSubscription<T> result = _createSubscription(cancelOnError); 70 return _createSubscription(onData, onError, onDone, cancelOnError);
71 result.onData(onData);
72 result.onError(onError);
73 result.onDone(onDone);
74 return result;
75 } 71 }
76 72
77 StreamSubscription<T> _createSubscription(bool cancelOnError) { 73 StreamSubscription<T> _createSubscription(
78 return new _ForwardingStreamSubscription<S, T>(this, cancelOnError); 74 void onData(T data),
75 Function onError,
76 void onDone(),
77 bool cancelOnError) {
78 return new _ForwardingStreamSubscription<S, T>(
79 this, onData, onError, onDone, cancelOnError);
79 } 80 }
80 81
81 // Override the following methods in subclasses to change the behavior. 82 // Override the following methods in subclasses to change the behavior.
82 83
83 void _handleData(S data, _EventSink<T> sink) { 84 void _handleData(S data, _EventSink<T> sink) {
84 var outputData = data; 85 var outputData = data;
85 sink._add(outputData); 86 sink._add(outputData);
86 } 87 }
87 88
88 void _handleError(error, StackTrace stackTrace, _EventSink<T> sink) { 89 void _handleError(error, StackTrace stackTrace, _EventSink<T> sink) {
89 sink._addError(error, stackTrace); 90 sink._addError(error, stackTrace);
90 } 91 }
91 92
92 void _handleDone(_EventSink<T> sink) { 93 void _handleDone(_EventSink<T> sink) {
93 sink._close(); 94 sink._close();
94 } 95 }
95 } 96 }
96 97
97 /** 98 /**
98 * Abstract superclass for subscriptions that forward to other subscriptions. 99 * Abstract superclass for subscriptions that forward to other subscriptions.
99 */ 100 */
100 class _ForwardingStreamSubscription<S, T> 101 class _ForwardingStreamSubscription<S, T>
101 extends _BufferingStreamSubscription<T> { 102 extends _BufferingStreamSubscription<T> {
102 final _ForwardingStream<S, T> _stream; 103 final _ForwardingStream<S, T> _stream;
103 104
104 StreamSubscription<S> _subscription; 105 StreamSubscription<S> _subscription;
105 106
106 _ForwardingStreamSubscription(this._stream, bool cancelOnError) 107 _ForwardingStreamSubscription(this._stream, void onData(T data),
107 : super(cancelOnError) { 108 Function onError, void onDone(),
109 bool cancelOnError)
110 : super(onData, onError, onDone, cancelOnError) {
108 _subscription = _stream._source.listen(_handleData, 111 _subscription = _stream._source.listen(_handleData,
109 onError: _handleError, 112 onError: _handleError,
110 onDone: _handleDone); 113 onDone: _handleDone);
111 } 114 }
112 115
113 // _StreamSink interface. 116 // _StreamSink interface.
114 // Transformers sending more than one event have no way to know if the stream 117 // Transformers sending more than one event have no way to know if the stream
115 // is canceled or closed after the first, so we just ignore remaining events. 118 // is canceled or closed after the first, so we just ignore remaining events.
116 119
117 void _add(T data) { 120 void _add(T data) {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 sink._addError(e, s); 401 sink._addError(e, s);
399 return null; 402 return null;
400 } 403 }
401 if (!isEqual) { 404 if (!isEqual) {
402 sink._add(inputEvent); 405 sink._add(inputEvent);
403 _previous = inputEvent; 406 _previous = inputEvent;
404 } 407 }
405 } 408 }
406 } 409 }
407 } 410 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | sdk/lib/async/stream_transformers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698