OLD | NEW |
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.graph.package_graph; | 5 library barback.graph.package_graph; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import '../asset/asset_id.dart'; | 10 import '../asset/asset_id.dart'; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 /// Gets the asset node identified by [id]. | 122 /// Gets the asset node identified by [id]. |
123 /// | 123 /// |
124 /// If [id] is for a generated or transformed asset, this will wait until it | 124 /// If [id] is for a generated or transformed asset, this will wait until it |
125 /// has been created and return it. This means that the returned asset will | 125 /// has been created and return it. This means that the returned asset will |
126 /// always be [AssetState.AVAILABLE]. | 126 /// always be [AssetState.AVAILABLE]. |
127 /// | 127 /// |
128 /// If the asset cannot be found, returns null. | 128 /// If the asset cannot be found, returns null. |
129 Future<AssetNode> getAssetNode(AssetId id) { | 129 Future<AssetNode> getAssetNode(AssetId id) { |
130 return _inErrorZone/*<Future<AssetNode>>*/(() { | 130 return _inErrorZone<Future<AssetNode>>(() { |
131 var cascade = _cascades[id.package]; | 131 var cascade = _cascades[id.package]; |
132 if (cascade != null) return cascade.getAssetNode(id); | 132 if (cascade != null) return cascade.getAssetNode(id); |
133 return new Future.value(null); | 133 return new Future.value(null); |
134 }); | 134 }); |
135 } | 135 } |
136 | 136 |
137 /// Returns the stream of newly-emitted assets for the given package's | 137 /// Returns the stream of newly-emitted assets for the given package's |
138 /// cascade. | 138 /// cascade. |
139 /// | 139 /// |
140 /// If there's no cascade for [package], returns `null`. | 140 /// If there's no cascade for [package], returns `null`. |
(...skipping 10 matching lines...) Expand all Loading... |
151 /// | 151 /// |
152 /// Any transforms using [LazyTransformer]s will be forced to generate | 152 /// Any transforms using [LazyTransformer]s will be forced to generate |
153 /// concrete outputs, and those outputs will be returned. | 153 /// concrete outputs, and those outputs will be returned. |
154 Future<AssetSet> getAllAssets() { | 154 Future<AssetSet> getAllAssets() { |
155 for (var cascade in _cascades.values) { | 155 for (var cascade in _cascades.values) { |
156 _inErrorZone(() => cascade.forceAllTransforms()); | 156 _inErrorZone(() => cascade.forceAllTransforms()); |
157 } | 157 } |
158 | 158 |
159 if (_status != NodeStatus.IDLE) { | 159 if (_status != NodeStatus.IDLE) { |
160 // A build is still ongoing, so wait for it to complete and try again. | 160 // A build is still ongoing, so wait for it to complete and try again. |
161 return results.first.then/*<Future<AssetSet>>*/((_) => getAllAssets()); | 161 return results.first.then<Future<AssetSet>>((_) => getAllAssets()); |
162 } | 162 } |
163 | 163 |
164 // If an unexpected error occurred, complete with that. | 164 // If an unexpected error occurred, complete with that. |
165 if (_lastUnexpectedError != null) { | 165 if (_lastUnexpectedError != null) { |
166 var error = _lastUnexpectedError; | 166 var error = _lastUnexpectedError; |
167 _lastUnexpectedError = null; | 167 _lastUnexpectedError = null; |
168 return new Future.error(error, _lastUnexpectedErrorTrace); | 168 return new Future.error(error, _lastUnexpectedErrorTrace); |
169 } | 169 } |
170 | 170 |
171 // If the last build completed with an error, complete the future with it. | 171 // If the last build completed with an error, complete the future with it. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 }); | 267 }); |
268 } | 268 } |
269 | 269 |
270 /// Run [body] in an error-handling [Zone] and pipe any unexpected errors to | 270 /// Run [body] in an error-handling [Zone] and pipe any unexpected errors to |
271 /// the error channel of [results]. | 271 /// the error channel of [results]. |
272 /// | 272 /// |
273 /// [body] can return a value or a [Future] that will be piped to the returned | 273 /// [body] can return a value or a [Future] that will be piped to the returned |
274 /// [Future]. If it throws a [BarbackException], that exception will be piped | 274 /// [Future]. If it throws a [BarbackException], that exception will be piped |
275 /// to the returned [Future] as well. Any other exceptions will be piped to | 275 /// to the returned [Future] as well. Any other exceptions will be piped to |
276 /// [results]. | 276 /// [results]. |
277 Future/*<T>*/ _inErrorZone/*<T>*/(/*=T*/ body()) { | 277 Future<T> _inErrorZone<T>(T body()) { |
278 var completer = new Completer/*<T>*/ .sync(); | 278 var completer = new Completer<T>.sync(); |
279 runZoned(() { | 279 runZoned(() { |
280 new Future.sync(body) | 280 new Future.sync(body) |
281 .then(completer.complete) | 281 .then(completer.complete) |
282 .catchError((error, stackTrace) { | 282 .catchError((error, stackTrace) { |
283 if (error is! BarbackException) throw error; | 283 if (error is! BarbackException) throw error; |
284 completer.completeError(error, stackTrace); | 284 completer.completeError(error, stackTrace); |
285 }); | 285 }); |
286 }, onError: (error, stackTrace) { | 286 }, onError: (error, stackTrace) { |
287 _lastUnexpectedError = error; | 287 _lastUnexpectedError = error; |
288 _lastUnexpectedErrorTrace = stackTrace; | 288 _lastUnexpectedErrorTrace = stackTrace; |
289 _resultsController.addError(error, stackTrace); | 289 _resultsController.addError(error, stackTrace); |
290 }); | 290 }); |
291 return completer.future; | 291 return completer.future; |
292 } | 292 } |
293 } | 293 } |
OLD | NEW |