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

Side by Side Diff: pkg/barback/lib/src/asset_graph.dart

Issue 18178021: Split AssetGraph.results into two streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/barback/test/asset_graph/errors_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library barback.asset_graph; 5 library barback.asset_graph;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'asset.dart'; 10 import 'asset.dart';
11 import 'asset_id.dart'; 11 import 'asset_id.dart';
12 import 'asset_provider.dart'; 12 import 'asset_provider.dart';
13 import 'asset_set.dart'; 13 import 'asset_set.dart';
14 import 'errors.dart'; 14 import 'errors.dart';
15 import 'change_batch.dart'; 15 import 'change_batch.dart';
16 import 'phase.dart'; 16 import 'phase.dart';
17 import 'transformer.dart'; 17 import 'transformer.dart';
18 18
19 /// The main build dependency manager. 19 /// The main build dependency manager.
20 /// 20 ///
21 /// For any given input file, it can tell which output files are affected by 21 /// For any given input file, it can tell which output files are affected by
22 /// it, and vice versa. 22 /// it, and vice versa.
23 class AssetGraph { 23 class AssetGraph {
24 final AssetProvider _provider; 24 final AssetProvider _provider;
25 25
26 final _phases = <Phase>[]; 26 final _phases = <Phase>[];
27 27
28 /// A stream that emits a [BuildResult] event each time the build is
Bob Nystrom 2013/07/10 20:19:44 remove "event"
nweiz 2013/07/10 20:45:09 Done.
29 /// completed, whether or not it succeeded.
30 ///
31 /// If a programming error in Barback itself occurs, it will be emitted
Bob Nystrom 2013/07/10 20:19:44 Instead of "programming error", maybe "unexpected
nweiz 2013/07/10 20:45:09 Done.
32 /// through this stream's error channel.
28 Stream<BuildResult> get results => _resultsController.stream; 33 Stream<BuildResult> get results => _resultsController.stream;
29 final _resultsController = new StreamController<BuildResult>.broadcast(); 34 final _resultsController = new StreamController<BuildResult>.broadcast();
30 35
36 /// A stream that emits any errors from the asset graph or the transformers.
37 ///
38 /// This emits errors as they're detected. If an error occurs in one part of
39 /// the asset graph, unrelated parts will continue building.
40 ///
41 /// This will not emit programming errors from Barback itself. Those will be
42 /// emitted through the [results] stream's error channel.
43 Stream get errors => _errorsController.stream;
Bob Nystrom 2013/07/10 20:19:44 I think we want a different name for this. Maybe "
nweiz 2013/07/10 20:45:09 I'd rather put different types of events in differ
Bob Nystrom 2013/07/10 21:38:16 SGTM.
44 final _errorsController = new StreamController.broadcast();
45
46 /// A queue that accumulates errors from a single build.
Bob Nystrom 2013/07/10 20:19:44 How about "The errors that have occurred since the
nweiz 2013/07/10 20:45:09 Done, slightly reworded.
47 ///
48 /// This will be empty if no build is occurring.
49 Queue _accumulatedErrors;
50
31 /// A future that completes when the currently running build process finishes. 51 /// A future that completes when the currently running build process finishes.
32 /// 52 ///
33 /// If no build it in progress, is `null`. 53 /// If no build it in progress, is `null`.
34 Future _processDone; 54 Future _processDone;
35 55
36 ChangeBatch _sourceChanges; 56 ChangeBatch _sourceChanges;
37 57
38 /// Creates a new [AssetGraph]. 58 /// Creates a new [AssetGraph].
39 /// 59 ///
40 /// It loads source assets using [provider] and then uses [transformerPhases] 60 /// It loads source assets using [provider] and then uses [transformerPhases]
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 132 }
113 133
114 /// Removes [removed] from the graph's known set of source assets. 134 /// Removes [removed] from the graph's known set of source assets.
115 void removeSources(Iterable<AssetId> removed) { 135 void removeSources(Iterable<AssetId> removed) {
116 if (_sourceChanges == null) _sourceChanges = new ChangeBatch(); 136 if (_sourceChanges == null) _sourceChanges = new ChangeBatch();
117 _sourceChanges.remove(removed); 137 _sourceChanges.remove(removed);
118 138
119 _waitForProcess(); 139 _waitForProcess();
120 } 140 }
121 141
122 /// Reports a process result with the given error then throws it.
123 void reportError(error) { 142 void reportError(error) {
124 _resultsController.add(new BuildResult(error)); 143 _accumulatedErrors.add(error);
144 _errorsController.add(error);
125 } 145 }
126 146
127 /// Starts the build process asynchronously if there is work to be done. 147 /// Starts the build process asynchronously if there is work to be done.
128 /// 148 ///
129 /// Returns a future that completes with the background processing is done. 149 /// Returns a future that completes with the background processing is done.
130 /// If there is no work to do, returns a future that completes immediately. 150 /// If there is no work to do, returns a future that completes immediately.
131 /// All errors that occur during processing will be caught (and routed to the 151 /// All errors that occur during processing will be caught (and routed to the
132 /// [results] stream) before they get to the returned future, so it is safe 152 /// [results] stream) before they get to the returned future, so it is safe
133 /// to discard it. 153 /// to discard it.
134 Future _waitForProcess() { 154 Future _waitForProcess() {
135 if (_processDone != null) return _processDone; 155 if (_processDone != null) return _processDone;
156
157 _accumulatedErrors = new Queue();
136 return _processDone = _process().then((_) { 158 return _processDone = _process().then((_) {
137 // Report the build completion. 159 // Report the build completion.
138 // TODO(rnystrom): Put some useful data in here. 160 // TODO(rnystrom): Put some useful data in here.
139 _resultsController.add(new BuildResult()); 161 _resultsController.add(new BuildResult(_accumulatedErrors));
140 }).catchError((error) { 162 }).catchError((error) {
141 // If we get here, it's an unexpected error. Runtime errors like missing 163 // If we get here, it's an unexpected error. Runtime errors like missing
142 // assets should be handled earlier. Errors from transformers or other 164 // assets should be handled earlier. Errors from transformers or other
143 // external code that barback calls into should be caught at that API 165 // external code that barback calls into should be caught at that API
144 // boundary. 166 // boundary.
145 // 167 //
146 // On the off chance we get here, pipe the error to the results stream 168 // On the off chance we get here, pipe the error to the results stream
147 // as an error. That will let applications handle it without it appearing 169 // as an error. That will let applications handle it without it appearing
148 // in the same path as "normal" errors that get reported. 170 // in the same path as "normal" errors that get reported.
149 _resultsController.addError(error); 171 _resultsController.addError(error);
150 }).whenComplete(() { 172 }).whenComplete(() {
151 _processDone = null; 173 _processDone = null;
174 _accumulatedErrors = null;
152 }); 175 });
153 } 176 }
154 177
155 /// Starts the background processing. 178 /// Starts the background processing.
156 /// 179 ///
157 /// Returns a future that completes when all assets have been processed. 180 /// Returns a future that completes when all assets have been processed.
158 Future _process() { 181 Future _process() {
159 return _processSourceChanges().then((_) { 182 return _processSourceChanges().then((_) {
160 // Find the first phase that has work to do and do it. 183 // Find the first phase that has work to do and do it.
161 var future; 184 var future;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 })); 231 }));
209 } 232 }
210 233
211 return Future.wait(futures).then((_) { 234 return Future.wait(futures).then((_) {
212 _phases.first.updateInputs(updated, changes.removed); 235 _phases.first.updateInputs(updated, changes.removed);
213 }); 236 });
214 }); 237 });
215 } 238 }
216 } 239 }
217 240
218 /// Used to report build results back from the asynchronous build process 241 /// An event indicating that the asset graph has finished building.
219 /// running in the background. 242 ///
243 /// A build can end either in success or failure. If there were no errors during
244 /// the build, it's considered to be a success; any errors render it a failure,
245 /// although individual assets may still have built successfully.
Bob Nystrom 2013/07/10 20:19:44 I don't think it's meaningful to say a build can s
nweiz 2013/07/10 20:45:09 I disagree. For users who care about the entire bu
220 class BuildResult { 246 class BuildResult {
221 /// The error that occurred, or `null` if the result is not an error. 247 /// All errors that occurred during the build.
222 final error; 248 final List errors;
223 249
224 /// `true` if this result is for a successful build. 250 /// `true` if the build succeeded.
225 bool get succeeded => error == null; 251 bool get succeeded => errors.isEmpty;
226 252
227 BuildResult([this.error]); 253 BuildResult(Iterable errors)
254 : errors = errors.toList();
228 } 255 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/test/asset_graph/errors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698