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

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

Issue 23926011: Rewrite Futures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove chained future cycle test. Created 7 years, 3 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 * Utility function to attach a stack trace to an [error] if it doesn't have 8 * Utility function to attach a stack trace to an [error] if it doesn't have
9 * one already. 9 * one already.
10 */ 10 */
11 _asyncError(Object error, Object stackTrace) { 11 _asyncError(Object error, Object stackTrace) {
12 if (stackTrace == null) return error; 12 if (stackTrace == null) return error;
13 if (getAttachedStackTrace(error) != null) return error; 13 if (getAttachedStackTrace(error) != null) return error;
14 _attachStackTrace(error, stackTrace); 14 _attachStackTrace(error, stackTrace);
15 return error; 15 return error;
16 } 16 }
17 17
18 /** Runs user code and takes actions depending on success or failure. */ 18 /** Runs user code and takes actions depending on success or failure. */
19 _runUserCode(userCode(), onSuccess(value), onError(error)) { 19 _runUserCode(userCode(), onSuccess(value), onError(error)) {
20 try { 20 try {
21 onSuccess(userCode()); 21 onSuccess(userCode());
22 } catch (e, s) { 22 } catch (e, s) {
23 onError(_asyncError(e, s)); 23 onError(_asyncError(e, s));
24 } 24 }
25 } 25 }
26 26
27 /** Helper function to make an onError argument to [_runUserCode]. */ 27 /** Helper function to make an onError argument to [_runUserCode]. */
28 _cancelAndError(StreamSubscription subscription, _FutureImpl future) => 28 _cancelAndError(StreamSubscription subscription, _Future future) =>
29 (error) { 29 (error) {
30 subscription.cancel(); 30 subscription.cancel();
31 future._setError(error); 31 future._completeError(error);
32 }; 32 };
33 33
34 34
35 /** 35 /**
36 * A [Stream] that forwards subscriptions to another stream. 36 * A [Stream] that forwards subscriptions to another stream.
37 * 37 *
38 * This stream implements [Stream], but forwards all subscriptions 38 * This stream implements [Stream], but forwards all subscriptions
39 * to an underlying stream, and wraps the returned subscription to 39 * to an underlying stream, and wraps the returned subscription to
40 * modify the events on the way. 40 * modify the events on the way.
41 * 41 *
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 449
450 void handleError(error, EventSink<T> sink) { 450 void handleError(error, EventSink<T> sink) {
451 _handleError(error, sink); 451 _handleError(error, sink);
452 } 452 }
453 453
454 void handleDone(EventSink<T> sink) { 454 void handleDone(EventSink<T> sink) {
455 _handleDone(sink); 455 _handleDone(sink);
456 } 456 }
457 } 457 }
458 458
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698