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

Unified Diff: sdk/lib/async/future_impl.dart

Issue 1966523003: Make _Future._chainForeignFuture not cause an assert. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/lib/async/future_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/future_impl.dart
diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
index eb4d6cfcaaf090a9c862cdaabeac192afdff1a69..dd07720aac3ede24c1cdf1dd9dcf944ff8fd6272 100644
--- a/sdk/lib/async/future_impl.dart
+++ b/sdk/lib/async/future_impl.dart
@@ -277,6 +277,11 @@ class _Future<T> implements Future<T> {
_state = _PENDING_COMPLETE;
}
+ void _clearPendingComplete() {
+ assert(_isPendingComplete);
+ _state = _INCOMPLETE;
+ }
+
AsyncError get _error {
assert(_hasError);
return _resultOrListeners;
@@ -405,7 +410,11 @@ class _Future<T> implements Future<T> {
try {
source.then((value) {
assert(target._isPendingComplete);
- target._completeWithValue(value);
+ // The "value" may be another future if the foreign future
+ // implementation is mis-behaving,
+ // so use _complete instead of _completeWithValue.
+ target._clearPendingComplete(); // Clear this first, it's set again.
+ target._complete(value);
},
// TODO(floitsch): eventually we would like to make this non-optional
// and dependent on the listeners of the target future. If none of
@@ -650,7 +659,7 @@ class _Future<T> implements Future<T> {
}
}
-
+
if (listener.handlesComplete) {
handleWhenCompleteCallback();
} else if (!hasError) {
@@ -662,7 +671,7 @@ class _Future<T> implements Future<T> {
handleError();
}
}
-
+
// If we changed zone, oldZone will not be null.
if (oldZone != null) Zone._leave(oldZone);
« no previous file with comments | « no previous file | tests/lib/async/future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698