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

Unified Diff: sdk/lib/_internal/pub/lib/src/utils.dart

Issue 323263002: Load parallel transformers in the same isolate. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix a typo Created 6 years, 6 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 | « sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/utils.dart
diff --git a/sdk/lib/_internal/pub/lib/src/utils.dart b/sdk/lib/_internal/pub/lib/src/utils.dart
index 1203f97b21affc20188624582360ccdd8045d553..c30c1ed50acf71fe36003a35d5bb0296041c5817 100644
--- a/sdk/lib/_internal/pub/lib/src/utils.dart
+++ b/sdk/lib/_internal/pub/lib/src/utils.dart
@@ -308,6 +308,25 @@ Map mapMap(Map map, keyFn(key, value), valueFn(key, value)) =>
/// The return values of [valueFn] are used as the values for the new map.
Map mapMapValues(Map map, fn(key, value)) => mapMap(map, (key, _) => key, fn);
+/// Like [listToMap], but [keyFn] and [valueFn] may return [Future]s.
+Future<Map> listToMapAsync(Iterable iter, keyFn(element), valueFn(element)) {
+ var map = new Map();
+ return Future.wait(iter.map((element) {
+ return Future.wait([
+ syncFuture(() => keyFn(element)),
+ syncFuture(() => valueFn(element))
+ ]).then((results) {
+ map[results[0]] = results[1];
+ });
+ })).then((_) => map);
+}
+
+/// Like [mapMap], but [keyFn] and [valueFn] may return [Future]s.
+Future<Map> mapMapAsync(Map map, keyFn(key, value), valueFn(key, value)) =>
+ listToMapAsync(map.keys,
+ (key) => keyFn(key, map[key]),
+ (key) => valueFn(key, map[key]));
+
/// Returns the shortest path from [start] to [end] in [graph].
///
/// The graph is represented by a map where each key is a vertex and the value
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698