| 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 'log.dart'; | 11 import 'log.dart'; |
| 12 import 'phase.dart'; | 12 import 'phase.dart'; |
| 13 import 'stream_pool.dart'; | 13 import 'stream_pool.dart'; |
| 14 import 'transformer_group.dart'; | 14 import 'transformer_group.dart'; |
| 15 | 15 |
| 16 /// A class that process all of the phases in a single transformer group. | 16 /// A class that processes all of the phases in a single transformer group. |
| 17 /// | 17 /// |
| 18 /// A group takes many inputs, processes them, and emits many outputs. | 18 /// A group takes many inputs, processes them, and emits many outputs. |
| 19 class GroupRunner { | 19 class GroupRunner { |
| 20 /// The group this runner runs. |
| 21 final TransformerGroup _group; |
| 22 |
| 23 /// A string describing the location of [this] in the transformer graph. |
| 24 final String _location; |
| 25 |
| 20 /// The phases defined by this group. | 26 /// The phases defined by this group. |
| 21 final _phases = new List<Phase>(); | 27 final _phases = new List<Phase>(); |
| 22 | 28 |
| 23 /// A stream that emits an event whenever this group becomes dirty and needs | 29 /// A stream that emits an event whenever this group becomes dirty and needs |
| 24 /// to be run. | 30 /// to be run. |
| 25 /// | 31 /// |
| 26 /// This may emit events when the group was already dirty or while processing | 32 /// This may emit events when the group was already dirty or while processing |
| 27 /// transforms. Events are emitted synchronously to ensure that the dirty | 33 /// transforms. Events are emitted synchronously to ensure that the dirty |
| 28 /// state is thoroughly propagated as soon as any assets are changed. | 34 /// state is thoroughly propagated as soon as any assets are changed. |
| 29 Stream get onDirty => _onDirtyPool.stream; | 35 Stream get onDirty => _onDirtyPool.stream; |
| 30 final _onDirtyPool = new StreamPool.broadcast(); | 36 final _onDirtyPool = new StreamPool.broadcast(); |
| 31 | 37 |
| 32 /// Whether this group is dirty and needs to be run. | 38 /// Whether this group is dirty and needs to be run. |
| 33 bool get isDirty => _phases.any((phase) => phase.isDirty); | 39 bool get isDirty => _phases.any((phase) => phase.isDirty); |
| 34 | 40 |
| 35 /// A stream that emits an event whenever any transforms in this group logs | 41 /// A stream that emits an event whenever any transforms in this group logs |
| 36 /// an entry. | 42 /// an entry. |
| 37 Stream<LogEntry> get onLog => _onLogPool.stream; | 43 Stream<LogEntry> get onLog => _onLogPool.stream; |
| 38 final _onLogPool = new StreamPool<LogEntry>.broadcast(); | 44 final _onLogPool = new StreamPool<LogEntry>.broadcast(); |
| 39 | 45 |
| 40 // 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 |
| 41 // 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 |
| 42 // AssetCascade. | 48 // AssetCascade. |
| 43 /// The set of outputs that has been returned by [process]. | 49 /// The set of outputs that has been returned by [process]. |
| 44 /// | 50 /// |
| 45 /// [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 |
| 46 /// ensure that it does so. | 52 /// ensure that it does so. |
| 47 final _alreadyEmittedOutputs = new Set<AssetNode>(); | 53 final _alreadyEmittedOutputs = new Set<AssetNode>(); |
| 48 | 54 |
| 49 GroupRunner(AssetCascade cascade, TransformerGroup group) { | 55 GroupRunner(AssetCascade cascade, this._group, this._location) { |
| 50 var lastPhase = new Phase(cascade, group.phases.first); | 56 var lastPhase = new Phase(cascade, _group.phases.first, _location); |
| 51 _phases.add(lastPhase); | 57 _phases.add(lastPhase); |
| 52 for (var phase in group.phases.skip(1)) { | 58 for (var phase in _group.phases.skip(1)) { |
| 53 lastPhase = lastPhase.addPhase(phase); | 59 lastPhase = lastPhase.addPhase(phase); |
| 54 _phases.add(lastPhase); | 60 _phases.add(lastPhase); |
| 55 } | 61 } |
| 56 | 62 |
| 57 for (var phase in _phases) { | 63 for (var phase in _phases) { |
| 58 _onDirtyPool.add(phase.onDirty); | 64 _onDirtyPool.add(phase.onDirty); |
| 59 _onLogPool.add(phase.onLog); | 65 _onLogPool.add(phase.onLog); |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 | 68 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 84 // If we get here, all phases are done processing. | 90 // If we get here, all phases are done processing. |
| 85 var newOutputs = _phases.last.availableOutputs | 91 var newOutputs = _phases.last.availableOutputs |
| 86 .difference(_alreadyEmittedOutputs); | 92 .difference(_alreadyEmittedOutputs); |
| 87 for (var output in newOutputs) { | 93 for (var output in newOutputs) { |
| 88 output.whenRemoved(() => _alreadyEmittedOutputs.remove(output)); | 94 output.whenRemoved(() => _alreadyEmittedOutputs.remove(output)); |
| 89 } | 95 } |
| 90 _alreadyEmittedOutputs.addAll(newOutputs); | 96 _alreadyEmittedOutputs.addAll(newOutputs); |
| 91 | 97 |
| 92 return new Future.value(newOutputs); | 98 return new Future.value(newOutputs); |
| 93 } | 99 } |
| 100 |
| 101 String toString() => "group in phase $_location for $_group"; |
| 94 } | 102 } |
| OLD | NEW |