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

Side by Side Diff: sdk/lib/async/stream_controller.dart

Issue 14251006: Remove AsyncError with Expando. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebuild DOM and rebase. Created 7 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 | Annotate | Revision Log
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 // ------------------------------------------------------------------- 7 // -------------------------------------------------------------------
8 // Controller for creating and adding events to a stream. 8 // Controller for creating and adding events to a stream.
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 10
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 bool get hasListener => stream._hasListener; 104 bool get hasListener => stream._hasListener;
105 105
106 /** 106 /**
107 * Send or queue a data event. 107 * Send or queue a data event.
108 */ 108 */
109 void add(T value) => stream._add(value); 109 void add(T value) => stream._add(value);
110 110
111 /** 111 /**
112 * Send or enqueue an error event. 112 * Send or enqueue an error event.
113 * 113 *
114 * If [error] is not an [AsyncError], [error] and an optional [stackTrace]
115 * is combined into an [AsyncError] and sent this stream's listeners.
116 *
117 * Otherwise, if [error] is an [AsyncError], it is used directly as the
118 * error object reported to listeners, and the [stackTrace] is ignored.
119 *
120 * If a subscription has requested to be unsubscribed on errors, 114 * If a subscription has requested to be unsubscribed on errors,
121 * it will be unsubscribed after receiving this event. 115 * it will be unsubscribed after receiving this event.
122 */ 116 */
123 void addError(Object error, [Object stackTrace]) { 117 void addError(Object error, [Object stackTrace]) {
124 AsyncError asyncError; 118 if (stackTrace != null) {
125 if (error is AsyncError) { 119 // Force stack trace overwrite. Even if the error already contained
126 asyncError = error; 120 // a stack trace.
127 } else { 121 _attachStackTrace(error, stackTrace);
128 asyncError = new AsyncError(error, stackTrace);
129 } 122 }
130 stream._addError(asyncError); 123 stream._addError(error);
131 } 124 }
132 125
133 /** 126 /**
134 * Send or enqueue a "done" message. 127 * Send or enqueue a "done" message.
135 * 128 *
136 * The "done" message should be sent at most once by a stream, and it 129 * The "done" message should be sent at most once by a stream, and it
137 * should be the last message sent. 130 * should be the last message sent.
138 */ 131 */
139 void close() { stream._close(); } 132 void close() { stream._close(); }
140 } 133 }
141 134
142 typedef void _NotificationHandler(); 135 typedef void _NotificationHandler();
143 136
144 class _MultiControllerStream<T> extends _MultiStreamImpl<T> { 137 class _MultiControllerStream<T> extends _MultiStreamImpl<T> {
145 _NotificationHandler _subscriptionHandler; 138 _NotificationHandler _subscriptionHandler;
146 _NotificationHandler _pauseHandler; 139 _NotificationHandler _pauseHandler;
147 140
148 _MultiControllerStream(this._subscriptionHandler, this._pauseHandler); 141 _MultiControllerStream(this._subscriptionHandler, this._pauseHandler);
149 142
150 void _onSubscriptionStateChange() { 143 void _onSubscriptionStateChange() {
151 if (_subscriptionHandler != null) { 144 if (_subscriptionHandler != null) {
152 try { 145 try {
153 _subscriptionHandler(); 146 _subscriptionHandler();
154 } catch (e, s) { 147 } catch (e, s) {
155 new AsyncError(e, s).throwDelayed(); 148 _throwDelayed(e, s);
156 } 149 }
157 } 150 }
158 } 151 }
159 152
160 void _onPauseStateChange() { 153 void _onPauseStateChange() {
161 if (_pauseHandler != null) { 154 if (_pauseHandler != null) {
162 try { 155 try {
163 _pauseHandler(); 156 _pauseHandler();
164 } catch (e, s) { 157 } catch (e, s) {
165 new AsyncError(e, s).throwDelayed(); 158 _throwDelayed(e, s);
166 } 159 }
167 } 160 }
168 } 161 }
169 } 162 }
170 163
171 class _SingleControllerStream<T> extends _SingleStreamImpl<T> { 164 class _SingleControllerStream<T> extends _SingleStreamImpl<T> {
172 _NotificationHandler _subscriptionHandler; 165 _NotificationHandler _subscriptionHandler;
173 _NotificationHandler _pauseHandler; 166 _NotificationHandler _pauseHandler;
174 167
175 _SingleControllerStream(this._subscriptionHandler, this._pauseHandler); 168 _SingleControllerStream(this._subscriptionHandler, this._pauseHandler);
176 169
177 void _onSubscriptionStateChange() { 170 void _onSubscriptionStateChange() {
178 if (_subscriptionHandler != null) { 171 if (_subscriptionHandler != null) {
179 try { 172 try {
180 _subscriptionHandler(); 173 _subscriptionHandler();
181 } catch (e, s) { 174 } catch (e, s) {
182 new AsyncError(e, s).throwDelayed(); 175 _throwDelayed(e, s);
183 } 176 }
184 } 177 }
185 } 178 }
186 179
187 void _onPauseStateChange() { 180 void _onPauseStateChange() {
188 if (_pauseHandler != null) { 181 if (_pauseHandler != null) {
189 try { 182 try {
190 _pauseHandler(); 183 _pauseHandler();
191 } catch (e, s) { 184 } catch (e, s) {
192 new AsyncError(e, s).throwDelayed(); 185 _throwDelayed(e, s);
193 } 186 }
194 } 187 }
195 } 188 }
196 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698