| 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 'node_status.dart'; |
| 12 import 'phase.dart'; | 13 import 'phase.dart'; |
| 13 import 'stream_pool.dart'; | 14 import 'stream_pool.dart'; |
| 14 import 'transformer_group.dart'; | 15 import 'transformer_group.dart'; |
| 15 | 16 |
| 16 /// A class that processes all of the phases in a single transformer group. | 17 /// A class that processes all of the phases in a single transformer group. |
| 17 /// | 18 /// |
| 18 /// A group takes many inputs, processes them, and emits many outputs. | 19 /// A group takes many inputs, processes them, and emits many outputs. |
| 19 class GroupRunner { | 20 class GroupRunner { |
| 20 /// The group this runner runs. | 21 /// The group this runner runs. |
| 21 final TransformerGroup _group; | 22 final TransformerGroup _group; |
| 22 | 23 |
| 23 /// A string describing the location of [this] in the transformer graph. | 24 /// A string describing the location of [this] in the transformer graph. |
| 24 final String _location; | 25 final String _location; |
| 25 | 26 |
| 26 /// The phases defined by this group. | 27 /// The phases defined by this group. |
| 27 final _phases = new List<Phase>(); | 28 final _phases = new List<Phase>(); |
| 28 | 29 |
| 29 /// Whether [this] is dirty and still has more processing to do. | 30 /// How far along [this] is in processing its assets. |
| 30 bool get isDirty { | 31 NodeStatus get status { |
| 31 // Just check the last phase, since it will check all the previous phases | 32 // Just check the last phase, since it will check all the previous phases |
| 32 // itself. | 33 // itself. |
| 33 return _phases.last.isDirty; | 34 return _phases.last.status; |
| 34 } | 35 } |
| 35 | 36 |
| 36 /// A stream that emits an event whenever [this] is no longer dirty. | 37 /// A stream that emits an event every time the group's status changes. |
| 37 /// | 38 Stream<NodeStatus> get onStatusChange => _onStatusChange; |
| 38 /// This is synchronous in order to guarantee that it will emit an event as | 39 Stream _onStatusChange; |
| 39 /// soon as [isDirty] flips from `true` to `false`. | |
| 40 Stream get onDone => _onDone; | |
| 41 Stream _onDone; | |
| 42 | 40 |
| 43 /// A stream that emits any new assets emitted by [this]. | 41 /// A stream that emits any new assets emitted by [this]. |
| 44 /// | 42 /// |
| 45 /// Assets are emitted synchronously to ensure that any changes are thoroughly | 43 /// Assets are emitted synchronously to ensure that any changes are thoroughly |
| 46 /// propagated as soon as they occur. | 44 /// propagated as soon as they occur. |
| 47 Stream<AssetNode> get onAsset => _onAsset; | 45 Stream<AssetNode> get onAsset => _onAsset; |
| 48 Stream<AssetNode> _onAsset; | 46 Stream<AssetNode> _onAsset; |
| 49 | 47 |
| 50 /// A stream that emits an event whenever any transforms in this group logs | 48 /// A stream that emits an event whenever any transforms in this group logs |
| 51 /// an entry. | 49 /// an entry. |
| 52 Stream<LogEntry> get onLog => _onLogPool.stream; | 50 Stream<LogEntry> get onLog => _onLogPool.stream; |
| 53 final _onLogPool = new StreamPool<LogEntry>.broadcast(); | 51 final _onLogPool = new StreamPool<LogEntry>.broadcast(); |
| 54 | 52 |
| 55 GroupRunner(AssetCascade cascade, this._group, this._location) { | 53 GroupRunner(AssetCascade cascade, this._group, this._location) { |
| 56 _addPhase(new Phase(cascade, _location), []); | 54 _addPhase(new Phase(cascade, _location), []); |
| 57 for (var phase in _group.phases) { | 55 for (var phase in _group.phases) { |
| 58 _addPhase(_phases.last.addPhase(), phase); | 56 _addPhase(_phases.last.addPhase(), phase); |
| 59 } | 57 } |
| 60 | 58 |
| 61 _onAsset = _phases.last.onAsset; | 59 _onAsset = _phases.last.onAsset; |
| 62 _onDone = _phases.last.onDone; | 60 _onStatusChange = _phases.last.onStatusChange; |
| 63 } | 61 } |
| 64 | 62 |
| 65 /// Add a phase with [contents] to [this]'s list of phases. | 63 /// Add a phase with [contents] to [this]'s list of phases. |
| 66 /// | 64 /// |
| 67 /// [contents] should be an inner [Iterable] from a [TransformGroup.phases] | 65 /// [contents] should be an inner [Iterable] from a [TransformGroup.phases] |
| 68 /// value. | 66 /// value. |
| 69 void _addPhase(Phase phase, Iterable contents) { | 67 void _addPhase(Phase phase, Iterable contents) { |
| 70 _phases.add(phase); | 68 _phases.add(phase); |
| 71 _onLogPool.add(phase.onLog); | 69 _onLogPool.add(phase.onLog); |
| 72 phase.updateTransformers(contents); | 70 phase.updateTransformers(contents); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 88 /// Removes this group and all sub-phases within it. | 86 /// Removes this group and all sub-phases within it. |
| 89 void remove() { | 87 void remove() { |
| 90 _onLogPool.close(); | 88 _onLogPool.close(); |
| 91 for (var phase in _phases) { | 89 for (var phase in _phases) { |
| 92 phase.remove(); | 90 phase.remove(); |
| 93 } | 91 } |
| 94 } | 92 } |
| 95 | 93 |
| 96 String toString() => "group in phase $_location for $_group"; | 94 String toString() => "group in phase $_location for $_group"; |
| 97 } | 95 } |
| OLD | NEW |