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

Unified Diff: utils/pub/utils.dart

Issue 10340005: Add support for pub install. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More review changes Created 8 years, 8 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 cf9b456164996497779c7f188c998c36d4d84b75..39c86dfa274c5b42f403da69618b84c3f92a7bb7 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -18,4 +18,35 @@ 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()) {
+ var completer = new Completer();
+ future.then((_) => fn());
+ future.handleException((_) {
+ fn();
+ return false;
+ });
+}
+
+/**
+ * Flattens nested lists into a single list containing only non-list elements.
+ */
+List flatten(List nested) {
+ var result = [];
+ helper(list) {
+ for (var element in list) {
+ if (element is List) {
+ helper(element);
+ } else {
+ result.add(element);
+ }
+ }
+ }
+ helper(nested);
+ return result;
+}

Powered by Google App Engine
This is Rietveld 408576698