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

Unified Diff: utils/pub/utils.dart

Issue 12437022: Use scheduled_test for Pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-upload Created 7 years, 9 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 | utils/tests/pub/descriptor.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/utils.dart
diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
index 1d687f3e3c67048a5faa7a04e1fad30463803aa5..e713e860b4f2a880cf49236ff5ee385abc101b5a 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -337,3 +337,28 @@ void mapAddAll(Map destination, Map source) =>
/// replacing `+` with ` `.
String urlDecode(String encoded) =>
decodeUriComponent(encoded.replaceAll("+", " "));
+
+/// Takes a simple data structure (composed of [Map]s, [List]s, scalar objects,
+/// and [Future]s) and recursively resolves all the [Future]s contained within.
+/// Completes with the fully resolved structure.
+Future awaitObject(object) {
+ // Unroll nested futures.
+ if (object is Future) return object.then(awaitObject);
+ if (object is Collection) {
+ return Future.wait(object.map(awaitObject).toList());
+ }
+ if (object is! Map) return new Future.immediate(object);
+
+ var pairs = <Future<Pair>>[];
+ object.forEach((key, value) {
+ pairs.add(awaitObject(value)
+ .then((resolved) => new Pair(key, resolved)));
+ });
+ return Future.wait(pairs).then((resolvedPairs) {
+ var map = {};
+ for (var pair in resolvedPairs) {
+ map[pair.first] = pair.last;
+ }
+ return map;
+ });
+}
« no previous file with comments | « no previous file | utils/tests/pub/descriptor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698