| 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.group_runner; | 5 library barback.group_runner; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'asset_cascade.dart'; | 9 import 'asset_cascade.dart'; |
| 10 import 'asset_node.dart'; | 10 import 'asset_node.dart'; |
| 11 import 'asset_node_set.dart'; | |
| 12 import 'log.dart'; | 11 import 'log.dart'; |
| 13 import 'phase.dart'; | 12 import 'phase.dart'; |
| 14 import 'stream_pool.dart'; | 13 import 'stream_pool.dart'; |
| 15 import 'transformer_group.dart'; | 14 import 'transformer_group.dart'; |
| 16 | 15 |
| 17 /// A class that processes all of the phases in a single transformer group. | 16 /// A class that processes all of the phases in a single transformer group. |
| 18 /// | 17 /// |
| 19 /// A group takes many inputs, processes them, and emits many outputs. | 18 /// A group takes many inputs, processes them, and emits many outputs. |
| 20 class GroupRunner { | 19 class GroupRunner { |
| 21 /// The group this runner runs. | 20 /// The group this runner runs. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 Stream<LogEntry> get onLog => _onLogPool.stream; | 43 Stream<LogEntry> get onLog => _onLogPool.stream; |
| 45 final _onLogPool = new StreamPool<LogEntry>.broadcast(); | 44 final _onLogPool = new StreamPool<LogEntry>.broadcast(); |
| 46 | 45 |
| 47 // TODO(nweiz): move to a more push-based way of propagating outputs and get | 46 // TODO(nweiz): move to a more push-based way of propagating outputs and get |
| 48 // rid of this. Once that's done, see if we can unify GroupRunner and | 47 // rid of this. Once that's done, see if we can unify GroupRunner and |
| 49 // AssetCascade. | 48 // AssetCascade. |
| 50 /// The set of outputs that has been returned by [process]. | 49 /// The set of outputs that has been returned by [process]. |
| 51 /// | 50 /// |
| 52 /// [process] is expected to only return new outputs, so this is used to | 51 /// [process] is expected to only return new outputs, so this is used to |
| 53 /// ensure that it does so. | 52 /// ensure that it does so. |
| 54 final _alreadyEmittedOutputs = new AssetNodeSet(); | 53 final _alreadyEmittedOutputs = new Set<AssetNode>(); |
| 55 | 54 |
| 56 GroupRunner(AssetCascade cascade, this._group, this._location) { | 55 GroupRunner(AssetCascade cascade, this._group, this._location) { |
| 57 var lastPhase = new Phase(cascade, _group.phases.first, _location); | 56 var lastPhase = new Phase(cascade, _group.phases.first, _location); |
| 58 _phases.add(lastPhase); | 57 _phases.add(lastPhase); |
| 59 for (var phase in _group.phases.skip(1)) { | 58 for (var phase in _group.phases.skip(1)) { |
| 60 lastPhase = lastPhase.addPhase(phase); | 59 lastPhase = lastPhase.addPhase(phase); |
| 61 _phases.add(lastPhase); | 60 _phases.add(lastPhase); |
| 62 } | 61 } |
| 63 | 62 |
| 64 for (var phase in _phases) { | 63 for (var phase in _phases) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 92 Future<Set<AssetNode>> process() { | 91 Future<Set<AssetNode>> process() { |
| 93 // Process the first phase that needs to do work. | 92 // Process the first phase that needs to do work. |
| 94 for (var phase in _phases) { | 93 for (var phase in _phases) { |
| 95 var future = phase.process(); | 94 var future = phase.process(); |
| 96 if (future != null) return future.then((_) => process()); | 95 if (future != null) return future.then((_) => process()); |
| 97 } | 96 } |
| 98 | 97 |
| 99 // If we get here, all phases are done processing. | 98 // If we get here, all phases are done processing. |
| 100 var newOutputs = _phases.last.availableOutputs | 99 var newOutputs = _phases.last.availableOutputs |
| 101 .difference(_alreadyEmittedOutputs); | 100 .difference(_alreadyEmittedOutputs); |
| 101 for (var output in newOutputs) { |
| 102 output.whenRemoved(() => _alreadyEmittedOutputs.remove(output)); |
| 103 } |
| 102 _alreadyEmittedOutputs.addAll(newOutputs); | 104 _alreadyEmittedOutputs.addAll(newOutputs); |
| 103 | 105 |
| 104 return new Future.value(newOutputs); | 106 return new Future.value(newOutputs); |
| 105 } | 107 } |
| 106 | 108 |
| 107 String toString() => "group in phase $_location for $_group"; | 109 String toString() => "group in phase $_location for $_group"; |
| 108 } | 110 } |
| OLD | NEW |