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

Side by Side Diff: utils/pub/error_group.dart

Issue 12086110: Use the dart:async Stream API thoroughly in Pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | « utils/pub/curl_client.dart ('k') | utils/pub/hosted_source.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library error_group; 5 library error_group;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 /// An [ErrorGroup] entangles the errors of multiple [Future]s and [Stream]s 9 /// An [ErrorGroup] entangles the errors of multiple [Future]s and [Stream]s
10 /// with one another. This allows APIs to expose multiple [Future]s and 10 /// with one another. This allows APIs to expose multiple [Future]s and
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (!_isDone) _completer.complete(value); 172 if (!_isDone) _completer.complete(value);
173 _isDone = true; 173 _isDone = true;
174 _group._signalFutureComplete(this); 174 _group._signalFutureComplete(this);
175 }).catchError((error) => _group._signalError(error)); 175 }).catchError((error) => _group._signalError(error));
176 176
177 // Make sure _completer.future doesn't automatically send errors to the 177 // Make sure _completer.future doesn't automatically send errors to the
178 // top-level. 178 // top-level.
179 _completer.future.catchError((_) {}); 179 _completer.future.catchError((_) {});
180 } 180 }
181 181
182 Future then(onValue(T value), {onError(AsyncError asyncError)}) { 182 Future then(onValue(value), {onError(AsyncError asyncError)}) {
183 _hasListeners = true; 183 _hasListeners = true;
184 return _completer.future.then(onValue, onError: onError); 184 return _completer.future.then(onValue, onError: onError);
185 } 185 }
186 186
187 Future catchError(onError(AsyncError asyncError), {bool test(Object error)}) { 187 Future catchError(onError(AsyncError asyncError), {bool test(Object error)}) {
188 _hasListeners = true; 188 _hasListeners = true;
189 return _completer.future.catchError(onError, test: test); 189 return _completer.future.catchError(onError, test: test);
190 } 190 }
191 191
192 Future whenComplete(void action()) { 192 Future whenComplete(void action()) {
193 _hasListeners = true; 193 _hasListeners = true;
194 return _completer.future.whenComplete(action); 194 return _completer.future.whenComplete(action);
195 } 195 }
196 196
197 Stream<T> asStream() { 197 Stream asStream() {
198 _hasListeners = true; 198 _hasListeners = true;
199 return _completer.future.asStream(); 199 return _completer.future.asStream();
200 } 200 }
201 201
202 /// Signal that an error from [_group] should be propagated through [this], 202 /// Signal that an error from [_group] should be propagated through [this],
203 /// unless it's already complete. 203 /// unless it's already complete.
204 void _signalError(AsyncError error) { 204 void _signalError(AsyncError error) {
205 if (!_isDone) _completer.completeError(error.error, error.stackTrace); 205 if (!_isDone) _completer.completeError(error.error, error.stackTrace);
206 _isDone = true; 206 _isDone = true;
207 } 207 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 void _signalError(AsyncError e) { 259 void _signalError(AsyncError e) {
260 if (_isDone) return; 260 if (_isDone) return;
261 _subscription.cancel(); 261 _subscription.cancel();
262 // Call these asynchronously to work around issue 7913. 262 // Call these asynchronously to work around issue 7913.
263 new Future.immediate(null).then((_) { 263 new Future.immediate(null).then((_) {
264 _controller.signalError(e.error, e.stackTrace); 264 _controller.signalError(e.error, e.stackTrace);
265 _controller.close(); 265 _controller.close();
266 }); 266 });
267 } 267 }
268 } 268 }
OLDNEW
« no previous file with comments | « utils/pub/curl_client.dart ('k') | utils/pub/hosted_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698