| 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.phase_input; | 5 library barback.phase_input; |
| 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'; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return callback(asset, _transformers); | 268 return callback(asset, _transformers); |
| 269 }).then((result) { | 269 }).then((result) { |
| 270 if (setEquals(oldTransformers, _transformers)) return result; | 270 if (setEquals(oldTransformers, _transformers)) return result; |
| 271 return _tryUntilStable(callback); | 271 return _tryUntilStable(callback); |
| 272 }); | 272 }); |
| 273 } | 273 } |
| 274 | 274 |
| 275 /// Processes the transforms for this input. | 275 /// Processes the transforms for this input. |
| 276 Future<Set<AssetNode>> process() { | 276 Future<Set<AssetNode>> process() { |
| 277 if (_adjustTransformersFuture == null) return _processTransforms(); | 277 if (_adjustTransformersFuture == null) return _processTransforms(); |
| 278 return _waitForInputs().then((_) => _processTransforms()); | 278 return _waitForTransformers(() => _processTransforms()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 Future _waitForInputs() { | 281 /// Runs [callback] once all the transformers are adjusted correctly and the |
| 282 // Return a synchronous future so we can be sure [_adjustTransformers] isn't | 282 /// input is ready to be processed. |
| 283 // called between now and when the Future completes. | 283 /// |
| 284 if (_adjustTransformersFuture == null) return new Future.sync(() {}); | 284 /// If the transformers are already properly adjusted, [callback] is called |
| 285 return _adjustTransformersFuture.then((_) => _waitForInputs()); | 285 /// synchronously to ensure that [_adjustTransformers] isn't called before the |
| 286 /// callback. |
| 287 Future _waitForTransformers(callback()) { |
| 288 if (_adjustTransformersFuture == null) return new Future.sync(callback); |
| 289 return _adjustTransformersFuture.then( |
| 290 (_) => _waitForTransformers(callback)); |
| 286 } | 291 } |
| 287 | 292 |
| 288 /// Applies all currently wired up and dirty transforms. | 293 /// Applies all currently wired up and dirty transforms. |
| 289 Future<Set<AssetNode>> _processTransforms() { | 294 Future<Set<AssetNode>> _processTransforms() { |
| 290 if (input.state.isRemoved) return new Future.value(new Set()); | 295 if (input.state.isRemoved) return new Future.value(new Set()); |
| 291 | 296 |
| 292 if (_passThroughController != null) { | 297 if (_passThroughController != null) { |
| 293 if (!_newPassThrough) return new Future.value(new Set()); | 298 if (!_newPassThrough) return new Future.value(new Set()); |
| 294 _newPassThrough = false; | 299 _newPassThrough = false; |
| 295 return new Future.value( | 300 return new Future.value( |
| 296 new Set<AssetNode>.from([_passThroughController.node])); | 301 new Set<AssetNode>.from([_passThroughController.node])); |
| 297 } | 302 } |
| 298 | 303 |
| 299 return Future.wait(_transforms.map((transform) { | 304 return Future.wait(_transforms.map((transform) { |
| 300 if (!transform.isDirty) return new Future.value(new Set()); | 305 if (!transform.isDirty) return new Future.value(new Set()); |
| 301 return transform.apply(); | 306 return transform.apply(); |
| 302 })).then((outputs) => unionAll(outputs)); | 307 })).then((outputs) => unionAll(outputs)); |
| 303 } | 308 } |
| 304 } | 309 } |
| OLD | NEW |