| 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 /** Runs user code and takes actions depending on success or failure. */ | 7 /** Runs user code and takes actions depending on success or failure. */ |
| 8 _runUserCode(userCode(), | 8 _runUserCode(userCode(), |
| 9 onSuccess(value), | 9 onSuccess(value), |
| 10 onError(error, StackTrace stackTrace)) { | 10 onError(error, StackTrace stackTrace)) { |
| 11 try { | 11 try { |
| 12 onSuccess(userCode()); | 12 onSuccess(userCode()); |
| 13 } catch (e, s) { | 13 } catch (e, s) { |
| 14 AsyncError replacement = Zone.current.errorCallback(e, s); | 14 AsyncError replacement = Zone.current.errorCallback(e, s); |
| 15 if (replacement == null) { | 15 if (replacement == null) { |
| 16 onError(e, s); | 16 onError(e, s); |
| 17 } else { | 17 } else { |
| 18 onError(replacement.error, replacement.stackTrace); | 18 var error = _nonNullError(replacement.error); |
| 19 var stackTrace = replacement.stackTrace; |
| 20 onError(error, stackTrace); |
| 19 } | 21 } |
| 20 } | 22 } |
| 21 } | 23 } |
| 22 | 24 |
| 23 /** Helper function to cancel a subscription and wait for the potential future, | 25 /** Helper function to cancel a subscription and wait for the potential future, |
| 24 before completing with an error. */ | 26 before completing with an error. */ |
| 25 void _cancelAndError(StreamSubscription subscription, | 27 void _cancelAndError(StreamSubscription subscription, |
| 26 _Future future, | 28 _Future future, |
| 27 error, | 29 error, |
| 28 StackTrace stackTrace) { | 30 StackTrace stackTrace) { |
| 29 var cancelFuture = subscription.cancel(); | 31 var cancelFuture = subscription.cancel(); |
| 30 if (cancelFuture is Future) { | 32 if (cancelFuture is Future) { |
| 31 cancelFuture.whenComplete(() => future._completeError(error, stackTrace)); | 33 cancelFuture.whenComplete(() => future._completeError(error, stackTrace)); |
| 32 } else { | 34 } else { |
| 33 future._completeError(error, stackTrace); | 35 future._completeError(error, stackTrace); |
| 34 } | 36 } |
| 35 } | 37 } |
| 36 | 38 |
| 37 void _cancelAndErrorWithReplacement(StreamSubscription subscription, | 39 void _cancelAndErrorWithReplacement(StreamSubscription subscription, |
| 38 _Future future, | 40 _Future future, |
| 39 error, StackTrace stackTrace) { | 41 error, StackTrace stackTrace) { |
| 40 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 42 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 41 if (replacement != null) { | 43 if (replacement != null) { |
| 42 error = replacement.error; | 44 error = _nonNullError(replacement.error); |
| 43 stackTrace = replacement.stackTrace; | 45 stackTrace = replacement.stackTrace; |
| 44 } | 46 } |
| 45 _cancelAndError(subscription, future, error, stackTrace); | 47 _cancelAndError(subscription, future, error, stackTrace); |
| 46 } | 48 } |
| 47 | 49 |
| 48 /** Helper function to make an onError argument to [_runUserCode]. */ | 50 /** Helper function to make an onError argument to [_runUserCode]. */ |
| 49 _cancelAndErrorClosure(StreamSubscription subscription, _Future future) => | 51 _cancelAndErrorClosure(StreamSubscription subscription, _Future future) => |
| 50 ((error, StackTrace stackTrace) => _cancelAndError( | 52 ((error, StackTrace stackTrace) => _cancelAndError( |
| 51 subscription, future, error, stackTrace)); | 53 subscription, future, error, stackTrace)); |
| 52 | 54 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 182 } |
| 181 | 183 |
| 182 // ------------------------------------------------------------------- | 184 // ------------------------------------------------------------------- |
| 183 // Stream transformers used by the default Stream implementation. | 185 // Stream transformers used by the default Stream implementation. |
| 184 // ------------------------------------------------------------------- | 186 // ------------------------------------------------------------------- |
| 185 | 187 |
| 186 typedef bool _Predicate<T>(T value); | 188 typedef bool _Predicate<T>(T value); |
| 187 | 189 |
| 188 void _addErrorWithReplacement(_EventSink sink, error, stackTrace) { | 190 void _addErrorWithReplacement(_EventSink sink, error, stackTrace) { |
| 189 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); | 191 AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
| 190 if (replacement == null) { | 192 if (replacement != null) { |
| 191 sink._addError(error, stackTrace); | 193 error = _nonNullError(replacement.error); |
| 192 } else { | 194 stackTrace = replacement.stackTrace; |
| 193 sink._addError(replacement.error, replacement.stackTrace); | |
| 194 } | 195 } |
| 196 sink._addError(error, stackTrace); |
| 195 } | 197 } |
| 196 | 198 |
| 197 | 199 |
| 198 class _WhereStream<T> extends _ForwardingStream<T, T> { | 200 class _WhereStream<T> extends _ForwardingStream<T, T> { |
| 199 final _Predicate<T> _test; | 201 final _Predicate<T> _test; |
| 200 | 202 |
| 201 _WhereStream(Stream<T> source, bool test(T value)) | 203 _WhereStream(Stream<T> source, bool test(T value)) |
| 202 : _test = test, super(source); | 204 : _test = test, super(source); |
| 203 | 205 |
| 204 void _handleData(T inputEvent, _EventSink<T> sink) { | 206 void _handleData(T inputEvent, _EventSink<T> sink) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 _addErrorWithReplacement(sink, e, s); | 429 _addErrorWithReplacement(sink, e, s); |
| 428 return null; | 430 return null; |
| 429 } | 431 } |
| 430 if (!isEqual) { | 432 if (!isEqual) { |
| 431 sink._add(inputEvent); | 433 sink._add(inputEvent); |
| 432 _previous = inputEvent; | 434 _previous = inputEvent; |
| 433 } | 435 } |
| 434 } | 436 } |
| 435 } | 437 } |
| 436 } | 438 } |
| OLD | NEW |