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

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

Issue 11824032: Make a Future returned by the action of Future.whenCompelete delay. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
Index: sdk/lib/async/future_impl.dart
diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart
index 351e5b961e7ace93a1957013d1431d495c3ca809..983847948d8c27e487604a0679d3b0ec8df75664 100644
--- a/sdk/lib/async/future_impl.dart
+++ b/sdk/lib/async/future_impl.dart
@@ -157,7 +157,7 @@ class _FutureImpl<T> implements Future<T> {
}
}
- Future<T> whenComplete(void action()) {
+ Future<T> whenComplete(Future action()) {
_WhenFuture<T> whenFuture = new _WhenFuture<T>(action);
if (!_isComplete) {
_addListener(whenFuture);
@@ -416,7 +416,16 @@ class _WhenFuture<T> extends _TransformFuture<T, T> {
void _sendValue(T value) {
try {
- _action();
+ var result = _action();
+ if (result is Future) {
+ Future resultFuture = result;
+ result.then((_) {
+ _setValue(value);P
floitsch 2013/01/09 17:10:13 ;P ? ;)
Lasse Reichstein Nielsen 2013/01/10 07:02:33 ;-P Removed.
+ }, onError: (AsyncError e) {
+ _setError(e);
+ });
+ return;
+ }
} catch (e, s) {
_setError(new AsyncError(e, s));
return;
@@ -426,7 +435,18 @@ class _WhenFuture<T> extends _TransformFuture<T, T> {
void _sendError(AsyncError error) {
try {
- _action();
+ var result = _action();
+ if (result is Future) {
+ Future resultFuture = result;
+ result.then((_) {
+ _setError(error);
+ }, onError: (AsyncError e) {
+ // TODO(lrn): Find a way to combine error into the
+ // resulting error.
+ _setError(e);
+ });
+ return;
+ }
} catch (e, s) {
error = new AsyncError.withCause(e, s, error);
}
@@ -454,7 +474,7 @@ class _FutureWrapper<T> implements Future<T> {
return _future.catchError(function, test: test);
}
- Future whenComplete(void action()) {
+ Future whenComplete(Future action()) {
floitsch 2013/01/09 17:10:13 remove type completely.
Lasse Reichstein Nielsen 2013/01/10 07:02:33 Done.
return _future.whenComplete(action);
}

Powered by Google App Engine
This is Rietveld 408576698