| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library barback.graph.group_runner; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import '../asset/asset_node.dart'; | |
| 10 import '../log.dart'; | |
| 11 import '../transformer/transformer_group.dart'; | |
| 12 import '../utils/stream_pool.dart'; | |
| 13 import 'node_status.dart'; | |
| 14 import 'phase.dart'; | |
| 15 | |
| 16 /// A class that processes all of the phases in a single transformer group. | |
| 17 /// | |
| 18 /// A group takes many inputs, processes them, and emits many outputs. | |
| 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 | |
| 26 /// The phases defined by this group. | |
| 27 final _phases = new List<Phase>(); | |
| 28 | |
| 29 /// How far along [this] is in processing its assets. | |
| 30 NodeStatus get status { | |
| 31 // Just check the last phase, since it will check all the previous phases | |
| 32 // itself. | |
| 33 return _phases.last.status; | |
| 34 } | |
| 35 | |
| 36 /// A stream that emits an event every time the group's status changes. | |
| 37 Stream<NodeStatus> get onStatusChange => _onStatusChange; | |
| 38 Stream _onStatusChange; | |
| 39 | |
| 40 /// A stream that emits any new assets emitted by [this]. | |
| 41 /// | |
| 42 /// Assets are emitted synchronously to ensure that any changes are thoroughly | |
| 43 /// propagated as soon as they occur. | |
| 44 Stream<AssetNode> get onAsset => _onAsset; | |
| 45 Stream<AssetNode> _onAsset; | |
| 46 | |
| 47 /// A stream that emits an event whenever any transforms in this group logs | |
| 48 /// an entry. | |
| 49 Stream<LogEntry> get onLog => _onLogPool.stream; | |
| 50 final _onLogPool = new StreamPool<LogEntry>.broadcast(); | |
| 51 | |
| 52 GroupRunner(Phase previous, this._group, this._location) { | |
| 53 _addPhase(previous.addPhase(_location), []); | |
| 54 for (var phase in _group.phases) { | |
| 55 _addPhase(_phases.last.addPhase(), phase); | |
| 56 } | |
| 57 | |
| 58 _onAsset = _phases.last.onAsset; | |
| 59 _onStatusChange = _phases.last.onStatusChange; | |
| 60 } | |
| 61 | |
| 62 /// Add a phase with [contents] to [this]'s list of phases. | |
| 63 /// | |
| 64 /// [contents] should be an inner [Iterable] from a [TransformGroup.phases] | |
| 65 /// value. | |
| 66 void _addPhase(Phase phase, Iterable contents) { | |
| 67 _phases.add(phase); | |
| 68 _onLogPool.add(phase.onLog); | |
| 69 phase.updateTransformers(contents); | |
| 70 } | |
| 71 | |
| 72 /// Force all [LazyTransformer]s' transforms in this group to begin producing | |
| 73 /// concrete assets. | |
| 74 void forceAllTransforms() { | |
| 75 for (var phase in _phases) { | |
| 76 phase.forceAllTransforms(); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 /// Removes this group and all sub-phases within it. | |
| 81 void remove() { | |
| 82 _onLogPool.close(); | |
| 83 for (var phase in _phases) { | |
| 84 phase.remove(); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 String toString() => "group in phase $_location for $_group"; | |
| 89 } | |
| OLD | NEW |