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.transform_node; | 5 library barback.graph.transform_node; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
| 9 import 'package:async/async.dart'; |
| 10 |
9 import '../asset/asset.dart'; | 11 import '../asset/asset.dart'; |
10 import '../asset/asset_id.dart'; | 12 import '../asset/asset_id.dart'; |
11 import '../asset/asset_node.dart'; | 13 import '../asset/asset_node.dart'; |
12 import '../asset/asset_node_set.dart'; | 14 import '../asset/asset_node_set.dart'; |
13 import '../errors.dart'; | 15 import '../errors.dart'; |
14 import '../log.dart'; | 16 import '../log.dart'; |
15 import '../transformer/aggregate_transform.dart'; | 17 import '../transformer/aggregate_transform.dart'; |
16 import '../transformer/aggregate_transformer.dart'; | 18 import '../transformer/aggregate_transformer.dart'; |
17 import '../transformer/declaring_aggregate_transform.dart'; | 19 import '../transformer/declaring_aggregate_transform.dart'; |
18 import '../transformer/declaring_aggregate_transformer.dart'; | 20 import '../transformer/declaring_aggregate_transformer.dart'; |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 438 |
437 _state = _State.DECLARING; | 439 _state = _State.DECLARING; |
438 var controller = new DeclaringAggregateTransformController(this); | 440 var controller = new DeclaringAggregateTransformController(this); |
439 _declareController = controller; | 441 _declareController = controller; |
440 _streams.onLogPool.add(controller.onLog); | 442 _streams.onLogPool.add(controller.onLog); |
441 for (var primary in _primaries) { | 443 for (var primary in _primaries) { |
442 controller.addId(primary.id); | 444 controller.addId(primary.id); |
443 } | 445 } |
444 _maybeFinishDeclareController(); | 446 _maybeFinishDeclareController(); |
445 | 447 |
446 syncFuture(() { | 448 new Future.sync(() { |
447 return (transformer as DeclaringAggregateTransformer) | 449 return (transformer as DeclaringAggregateTransformer) |
448 .declareOutputs(controller.transform); | 450 .declareOutputs(controller.transform); |
449 }).whenComplete(() { | 451 }).whenComplete(() { |
450 // Cancel the controller here even if `declareOutputs` wasn't interrupted. | 452 // Cancel the controller here even if `declareOutputs` wasn't interrupted. |
451 // Since the declaration is finished, we want to close out the | 453 // Since the declaration is finished, we want to close out the |
452 // controller's streams. | 454 // controller's streams. |
453 controller.cancel(); | 455 controller.cancel(); |
454 _declareController = null; | 456 _declareController = null; |
455 }).then((_) { | 457 }).then((_) { |
456 if (_isRemoved) return; | 458 if (_isRemoved) return; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 _applyController = controller; | 638 _applyController = controller; |
637 _streams.onLogPool.add(controller.onLog); | 639 _streams.onLogPool.add(controller.onLog); |
638 for (var primary in _primaries) { | 640 for (var primary in _primaries) { |
639 if (!primary.state.isAvailable) continue; | 641 if (!primary.state.isAvailable) continue; |
640 controller.addInput(primary.asset); | 642 controller.addInput(primary.asset); |
641 } | 643 } |
642 _maybeFinishApplyController(); | 644 _maybeFinishApplyController(); |
643 | 645 |
644 var transformCounterTimer; | 646 var transformCounterTimer; |
645 | 647 |
646 return syncFuture(() { | 648 return DelegatingFuture.typed(new Future.sync(() { |
647 _timeInTransformer.reset(); | 649 _timeInTransformer.reset(); |
648 _timeAwaitingInputs.reset(); | 650 _timeAwaitingInputs.reset(); |
649 _timeInTransformer.start(); | 651 _timeInTransformer.start(); |
650 | 652 |
651 transformCounterTimer = new Timer.periodic(_applyLogDuration, (_) { | 653 transformCounterTimer = new Timer.periodic(_applyLogDuration, (_) { |
652 if (_streams.onLogController.isClosed || | 654 if (_streams.onLogController.isClosed || |
653 !_timeInTransformer.isRunning) { | 655 !_timeInTransformer.isRunning) { |
654 return; | 656 return; |
655 } | 657 } |
656 | 658 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 return false; | 720 return false; |
719 }).catchError((error, stackTrace) { | 721 }).catchError((error, stackTrace) { |
720 // If the transform became dirty while processing, ignore any errors from | 722 // If the transform became dirty while processing, ignore any errors from |
721 // it. | 723 // it. |
722 if (_state == _State.NEEDS_APPLY || _isRemoved) return false; | 724 if (_state == _State.NEEDS_APPLY || _isRemoved) return false; |
723 | 725 |
724 // Catch all transformer errors and pipe them to the results stream. This | 726 // Catch all transformer errors and pipe them to the results stream. This |
725 // is so a broken transformer doesn't take down the whole graph. | 727 // is so a broken transformer doesn't take down the whole graph. |
726 phase.cascade.reportError(_wrapException(error, stackTrace)); | 728 phase.cascade.reportError(_wrapException(error, stackTrace)); |
727 return true; | 729 return true; |
728 }); | 730 })); |
729 } | 731 } |
730 | 732 |
731 /// Handle the results of running [Transformer.apply]. | 733 /// Handle the results of running [Transformer.apply]. |
732 /// | 734 /// |
733 /// [controller] should be the controller for the [AggegateTransform] passed | 735 /// [controller] should be the controller for the [AggegateTransform] passed |
734 /// to [AggregateTransformer.apply]. | 736 /// to [AggregateTransformer.apply]. |
735 void _handleApplyResults(AggregateTransformController controller) { | 737 void _handleApplyResults(AggregateTransformController controller) { |
736 _consumedPrimaries = controller.consumedPrimaries; | 738 _consumedPrimaries = controller.consumedPrimaries; |
737 | 739 |
738 var newOutputs = controller.outputs; | 740 var newOutputs = controller.outputs; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 /// declaring and [APPLYING] otherwise. If a primary input is added or | 916 /// declaring and [APPLYING] otherwise. If a primary input is added or |
915 /// removed, this will transition to [DECLARING]. | 917 /// removed, this will transition to [DECLARING]. |
916 static const APPLIED = const _State._("applied"); | 918 static const APPLIED = const _State._("applied"); |
917 | 919 |
918 final String name; | 920 final String name; |
919 | 921 |
920 const _State._(this.name); | 922 const _State._(this.name); |
921 | 923 |
922 String toString() => name; | 924 String toString() => name; |
923 } | 925 } |
OLD | NEW |