Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: pkg/barback/lib/src/group_runner.dart

Issue 261823008: Reorganize barback's source files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-add barback/lib/src/internal_asset.dart Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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.group_runner;
6
7 import 'dart:async';
8
9 import 'asset_cascade.dart';
10 import 'asset_node.dart';
11 import 'log.dart';
12 import 'node_status.dart';
13 import 'phase.dart';
14 import 'stream_pool.dart';
15 import 'transformer_group.dart';
16
17 /// A class that processes all of the phases in a single transformer group.
18 ///
19 /// A group takes many inputs, processes them, and emits many outputs.
20 class GroupRunner {
21 /// The group this runner runs.
22 final TransformerGroup _group;
23
24 /// A string describing the location of [this] in the transformer graph.
25 final String _location;
26
27 /// The phases defined by this group.
28 final _phases = new List<Phase>();
29
30 /// How far along [this] is in processing its assets.
31 NodeStatus get status {
32 // Just check the last phase, since it will check all the previous phases
33 // itself.
34 return _phases.last.status;
35 }
36
37 /// A stream that emits an event every time the group's status changes.
38 Stream<NodeStatus> get onStatusChange => _onStatusChange;
39 Stream _onStatusChange;
40
41 /// A stream that emits any new assets emitted by [this].
42 ///
43 /// Assets are emitted synchronously to ensure that any changes are thoroughly
44 /// propagated as soon as they occur.
45 Stream<AssetNode> get onAsset => _onAsset;
46 Stream<AssetNode> _onAsset;
47
48 /// A stream that emits an event whenever any transforms in this group logs
49 /// an entry.
50 Stream<LogEntry> get onLog => _onLogPool.stream;
51 final _onLogPool = new StreamPool<LogEntry>.broadcast();
52
53 GroupRunner(AssetCascade cascade, this._group, this._location) {
54 _addPhase(new Phase(cascade, _location), []);
55 for (var phase in _group.phases) {
56 _addPhase(_phases.last.addPhase(), phase);
57 }
58
59 _onAsset = _phases.last.onAsset;
60 _onStatusChange = _phases.last.onStatusChange;
61 }
62
63 /// Add a phase with [contents] to [this]'s list of phases.
64 ///
65 /// [contents] should be an inner [Iterable] from a [TransformGroup.phases]
66 /// value.
67 void _addPhase(Phase phase, Iterable contents) {
68 _phases.add(phase);
69 _onLogPool.add(phase.onLog);
70 phase.updateTransformers(contents);
71 }
72
73 /// Force all [LazyTransformer]s' transforms in this group to begin producing
74 /// concrete assets.
75 void forceAllTransforms() {
76 for (var phase in _phases) {
77 phase.forceAllTransforms();
78 }
79 }
80
81 /// Adds a new asset as an input for this group.
82 void addInput(AssetNode node) {
83 _phases.first.addInput(node);
84 }
85
86 /// Removes this group and all sub-phases within it.
87 void remove() {
88 _onLogPool.close();
89 for (var phase in _phases) {
90 phase.remove();
91 }
92 }
93
94 String toString() => "group in phase $_location for $_group";
95 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/graph/transformer_classifier.dart ('k') | pkg/barback/lib/src/internal_asset.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698