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

Unified Diff: utils/pub/utils.dart

Issue 11830017: Fix ALL the pub tests. (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: utils/pub/utils.dart
diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
index 2a800fa0ce59bd7d67e824321d220fcc218fbd20..ffde5622bb28cc31f9ab3255b2b001539887deb3 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -40,12 +40,6 @@ String padRight(String source, int length) {
return result.toString();
}
-/// Runs [fn] after [future] completes, whether it completes successfully or
-/// not. Essentially an asynchronous `finally` block.
-always(Future future, fn()) {
- future.catchError((_) {}).then((_) => fn());
-}
-
Bob Nystrom 2013/01/09 16:49:23 Yay!
/// Flattens nested lists inside an iterable into a single list containing only
/// non-list elements.
List flatten(Iterable nested) {
@@ -124,6 +118,25 @@ void chainToCompleter(Future future, Completer completer) {
onError: (e) => completer.completeError(e.error, e.stackTrace));
}
+/// Like [Future.whenComplete], except that [action] may return a [Future]. If
+/// it does, the returned [Future] won't complete until [action]'s [Future]
+/// completes.
+///
+/// The returned [Future] always has the same value as [future].
Bob Nystrom 2013/01/09 16:49:23 Since this is how then() and catchError() work, it
+Future asyncWhenComplete(Future future, Future action()) {
+ Future futurify(Future future) {
+ if (future != null) return future;
+ return new Future.immediate(null);
+ }
+
+ return future.then((result) => futurify(action()).then((_) => result),
+ onError: (e) {
+ return futurify(action()).then((_) {
+ throw e;
+ });
+ });
+}
+
// TODO(nweiz): unify the following functions with the utility functions in
// pkg/http.
@@ -194,3 +207,16 @@ getRealError(error) {
return error;
}
+
+// TODO(rnystrom): Remove this when #7781 is fixed.
Bob Nystrom 2013/01/09 16:49:23 "nweiz", not that it really matters. :)
+/// When an error is rethrown in an async callback, you can end up with nested
+/// AsyncErrors. This unwraps them to find the real originating stack trace.
+getRealStackTrace(error) {
+ var trace = null;
+ while (error is AsyncError) {
+ trace = error.stackTrace;
+ error = error.error;
+ }
+
+ return trace;
+}
« utils/pub/io.dart ('K') | « utils/pub/system_cache.dart ('k') | utils/pub/validator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698