Index: sdk/lib/async/future.dart |
diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart |
index 25398426df6949709a6ace0d33d171cf283b6399..0368ae8220b162734c257fc8b8d7526e35440e2c 100644 |
--- a/sdk/lib/async/future.dart |
+++ b/sdk/lib/async/future.dart |
@@ -485,7 +485,9 @@ abstract class Future<T> { |
try { |
result = f(); |
} catch (error, stackTrace) { |
- _completeWithErrorCallback(doneSignal, error, stackTrace); |
+ // Cannot use _completeWithErrorCallback because it completes |
+ // the future synchronously. |
+ _asyncCompleteWithErrorCallback(doneSignal, error, stackTrace); |
return; |
} |
if (result is Future<bool>) { |
@@ -873,5 +875,15 @@ void _completeWithErrorCallback(_Future result, error, stackTrace) { |
result._completeError(error, stackTrace); |
} |
+// Like [_completeWIthErrorCallback] but completes asynchronously. |
eernst
2017/04/06 11:45:57
Typo: `WIth` --> `With`.
|
+void _asyncCompleteWithErrorCallback(_Future result, error, stackTrace) { |
+ AsyncError replacement = Zone.current.errorCallback(error, stackTrace); |
+ if (replacement != null) { |
+ error = _nonNullError(replacement.error); |
+ stackTrace = replacement.stackTrace; |
+ } |
+ result._asyncCompleteError(error, stackTrace); |
+} |
+ |
/** Helper function that converts `null` to a [NullThrownError]. */ |
Object _nonNullError(Object error) => error ?? new NullThrownError(); |