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

Unified Diff: pkg/barback/lib/src/package_graph.dart

Issue 22824023: Start sketching out a buildAll() method. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't wrap a single error in an aggregate. Created 7 years, 4 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: pkg/barback/lib/src/package_graph.dart
diff --git a/pkg/barback/lib/src/package_graph.dart b/pkg/barback/lib/src/package_graph.dart
index 639deea6f49300cb47f6e4729e07d787a45a93e6..966f70a286dd179bac06814a4f74087e3899361c 100644
--- a/pkg/barback/lib/src/package_graph.dart
+++ b/pkg/barback/lib/src/package_graph.dart
@@ -9,6 +9,7 @@ import 'dart:async';
import 'asset_cascade.dart';
import 'asset_id.dart';
import 'asset_node.dart';
+import 'asset_set.dart';
import 'build_result.dart';
import 'errors.dart';
import 'package_provider.dart';
@@ -52,6 +53,10 @@ class PackageGraph {
Stream<BarbackException> get errors => _errors;
Stream<BarbackException> _errors;
+ /// The error associated with the previous build, or `null` if the last build
+ /// was successful.
+ BarbackException _lastError;
nweiz 2013/08/20 19:59:26 I don't understand this. Why does the user only ca
Bob Nystrom 2013/08/20 21:29:20 They don't. This was aggregating all cascades.
+
/// Creates a new [PackageGraph] that will transform assets in all packages
/// made available by [provider].
PackageGraph(this.provider) {
@@ -71,9 +76,24 @@ class PackageGraph {
// Include all build errors for all cascades. If no cascades have
// errors, the result will automatically be considered a success.
- _resultsController.add(new BuildResult(unionAll(
- _cascadeResults.values.map((result) => result.errors))));
- }, onError: _resultsController.addError);
+ var errors = unionAll(
+ _cascadeResults.values.map((result) => result.errors));
+
+ // Remember any errors for when [getAllAssets()] is called.
+ if (errors.length > 1) {
+ _lastError = new AggregateException(errors);
+ } else if (errors.length == 1) {
+ _lastError = errors.first;
+ } else {
+ // The build completed successfully.
+ _lastError = null;
+ }
+
+ _resultsController.add(new BuildResult(errors));
+ }, onError: (error) {
+ _lastError = error;
nweiz 2013/08/20 19:59:26 This is definitely not right. The error that's cau
Bob Nystrom 2013/08/20 21:29:20 Removed. I'm not sure what the best thing to do i
nweiz 2013/08/20 22:29:03 I think it's reasonable for [getAllAssets] to thro
Bob Nystrom 2013/08/21 18:10:23 Done.
+ _resultsController.addError(error);
+ });
}
_errors = mergeStreams(_cascades.values.map((cascade) => cascade.errors));
@@ -92,6 +112,27 @@ class PackageGraph {
return new Future.value(null);
}
+ /// Gets all output assets.
+ ///
+ /// If a build is currently in progress, waits until it completes. The
+ /// returned future will complete with an error if the build is not
+ /// successful.
+ Future<AssetSet> getAllAssets() {
+ if (_cascadeResults.values.any((result) => result == null)) {
nweiz 2013/08/20 19:59:26 _cascadeResults.values.contains(null)
Bob Nystrom 2013/08/20 21:29:20 Done.
+ // A build is still ongoing, so wait for it to complete and try again.
+ return results.first.then((_) => getAllAssets());
+ }
+
+ // If the build completed with an error, complete the future with it.
+ if (_lastError != null) return new Future.error(_lastError);
+
+ // Otherwise, return all of the final output assets.
+ var assets = unionAll(_cascades.values.map(
+ (cascade) => cascade.availableOutputs.toSet()));
+
+ return new Future.value(new AssetSet.from(assets));
+ }
+
/// Adds [sources] to the graph's known set of source assets.
///
/// Begins applying any transforms that can consume any of the sources. If a

Powered by Google App Engine
This is Rietveld 408576698