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 /** Utility function to create an [AsyncError] if [error] isn't one already. */ | 7 /** Utility function to create an [AsyncError] if [error] isn't one already. */ |
8 AsyncError _asyncError(Object error, Object stackTrace, [AsyncError cause]) { | 8 AsyncError _asyncError(Object error, Object stackTrace, [AsyncError cause]) { |
9 if (error is AsyncError) return error; | 9 if (error is AsyncError) return error; |
10 if (cause == null) return new AsyncError(error, stackTrace); | 10 if (cause == null) return new AsyncError(error, stackTrace); |
11 return new AsyncError.withCause(error, stackTrace, cause); | 11 return new AsyncError.withCause(error, stackTrace, cause); |
12 } | 12 } |
13 | 13 |
14 /** Runs user code and takes actions depending on success or failure. */ | 14 /** Runs user code and takes actions depending on success or failure. */ |
15 _runUserCode(userCode(), onSuccess(value), onError(AsyncError error), | 15 _runUserCode(userCode(), onSuccess(value), onError(AsyncError error), |
16 { AsyncError cause }) { | 16 { AsyncError cause }) { |
17 var result; | 17 var result; |
18 try { | 18 try { |
19 result = userCode(); | 19 result = userCode(); |
20 } on AsyncError catch (e) { | 20 } on AsyncError catch (e) { |
21 return onError(e); | 21 return onError(e); |
22 } catch (e, s) { | 22 } catch (e, s) { |
23 if (cause == null) { | 23 if (cause == null) { |
24 onError(new AsyncError(e, s)); | 24 onError(new AsyncError(e, s)); |
25 } else { | 25 } else { |
26 onError(new AsyncError.withCause(e, s, cause)); | 26 onError(new AsyncError.withCause(e, s, cause)); |
27 } | 27 } |
| 28 // onError is allowed to return. Don't execute the onSuccess below. |
| 29 return; |
28 } | 30 } |
29 onSuccess(result); | 31 onSuccess(result); |
30 } | 32 } |
31 | 33 |
32 /** Helper function to make an onError argument to [_runUserCode]. */ | 34 /** Helper function to make an onError argument to [_runUserCode]. */ |
33 _cancelAndError(StreamSubscription subscription, _FutureImpl future) => | 35 _cancelAndError(StreamSubscription subscription, _FutureImpl future) => |
34 (AsyncError error) { | 36 (AsyncError error) { |
35 subscription.cancel(); | 37 subscription.cancel(); |
36 future._setError(error); | 38 future._setError(error); |
37 }; | 39 }; |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 515 |
514 void handleError(AsyncError error, EventSink<T> sink) { | 516 void handleError(AsyncError error, EventSink<T> sink) { |
515 _handleError(error, sink); | 517 _handleError(error, sink); |
516 } | 518 } |
517 | 519 |
518 void handleDone(EventSink<T> sink) { | 520 void handleDone(EventSink<T> sink) { |
519 _handleDone(sink); | 521 _handleDone(sink); |
520 } | 522 } |
521 } | 523 } |
522 | 524 |
OLD | NEW |