OLD | NEW |
---|---|
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, _Future future) => | 28 _cancelAndError(StreamSubscription subscription, _Future future) => |
29 (error) { | 29 (error) { |
floitsch
2013/10/12 18:53:57
You will need to update this for the stack-trace a
Lasse Reichstein Nielsen
2013/10/14 11:32:33
And not make it curried.
Anders Johnsen
2013/10/16 11:52:21
Done.
Anders Johnsen
2013/10/16 11:52:21
Done.
| |
30 subscription.cancel(); | 30 var cancelFuture = subscription.cancel(); |
31 future._completeError(error); | 31 if (cancelFuture != null) { |
floitsch
2013/10/12 18:53:57
if (cancelFuture is Future)
Users are used to wri
Anders Johnsen
2013/10/16 11:52:21
Done.
| |
32 cancelFuture.whenComplete(() => future._completeError(error)); | |
33 } else { | |
34 future._completeError(error); | |
35 } | |
36 }; | |
37 | |
38 /** Helper function to make an onError argument to [_runUserCode]. */ | |
39 _cancelAndValue(StreamSubscription subscription, _Future future) => | |
40 (value) { | |
41 var cancelFuture = subscription.cancel(); | |
42 if (cancelFuture != null) { | |
floitsch
2013/10/12 18:53:57
ditto.
Anders Johnsen
2013/10/16 11:52:21
Done.
| |
43 cancelFuture.whenComplete(() => future._complete(value)); | |
44 } else { | |
45 future._complete(value); | |
46 } | |
32 }; | 47 }; |
33 | 48 |
34 | 49 |
35 /** | 50 /** |
36 * A [Stream] that forwards subscriptions to another stream. | 51 * A [Stream] that forwards subscriptions to another stream. |
37 * | 52 * |
38 * This stream implements [Stream], but forwards all subscriptions | 53 * This stream implements [Stream], but forwards all subscriptions |
39 * to an underlying stream, and wraps the returned subscription to | 54 * to an underlying stream, and wraps the returned subscription to |
40 * modify the events on the way. | 55 * modify the events on the way. |
41 * | 56 * |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 | 464 |
450 void handleError(error, EventSink<T> sink) { | 465 void handleError(error, EventSink<T> sink) { |
451 _handleError(error, sink); | 466 _handleError(error, sink); |
452 } | 467 } |
453 | 468 |
454 void handleDone(EventSink<T> sink) { | 469 void handleDone(EventSink<T> sink) { |
455 _handleDone(sink); | 470 _handleDone(sink); |
456 } | 471 } |
457 } | 472 } |
458 | 473 |
OLD | NEW |