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

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

Issue 25376003: Add support for transformer clusters to barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Expose the Operator class. Created 7 years, 2 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.cluster_runner;
6
7 import 'dart:async';
8
9 import 'asset_cascade.dart';
10 import 'asset_node.dart';
11 import 'phase.dart';
12 import 'stream_pool.dart';
13 import 'transformer_cluster.dart';
14
15 /// A class that handles a single transformer cluster.
Bob Nystrom 2013/10/04 21:47:50 "handles" -> "processes all of the phases in"
nweiz 2013/10/07 23:21:31 Done.
16 ///
17 /// A cluster takes a many inputs, processes them, and emits many outputs.
Bob Nystrom 2013/10/04 21:47:50 "a many" -> "many".
nweiz 2013/10/07 23:21:31 Done.
18 class ClusterRunner {
19 /// The phases defined by this cluster.
20 final _phases = new List<Phase>();
21
22 /// A stream that emits an event whenever this cluster becomes dirty and needs
23 /// to be run.
24 ///
25 /// This may emit events when the cluster was already dirty or while
26 /// processing transforms. Events are emitted synchronously to ensure that the
27 /// dirty state is thoroughly propagated as soon as any assets are changed.
28 Stream get onDirty => _onDirtyPool.stream;
29 final _onDirtyPool = new StreamPool.broadcast();
30
31 /// Whether this cluster is dirty and needs to be run.
32 bool get isDirty => _phases.any((phase) => phase.isDirty);
33
34 // TODO(nweiz): move to a more push-based way of propagating outputs and get
35 // rid of this.
Bob Nystrom 2013/10/04 21:47:50 Add: "Once that's done, see if TransformerGroup an
nweiz 2013/10/07 23:21:31 Done.
36 /// The set of outputs that has been returned by [process].
37 ///
38 /// [process] is expected to only return new outputs, so this is used to
39 /// ensure that it does so.
40 final _alreadyEmittedOutputs = new Set<AssetNode>();
41
42 ClusterRunner(AssetCascade cascade, TransformerCluster cluster) {
43 var lastPhase = new Phase(cascade, cluster.phases.first);
Bob Nystrom 2013/10/04 21:47:50 It feels weird to me that the phases within the cl
nweiz 2013/10/07 23:21:31 I find the fact that we're passing around the casc
Bob Nystrom 2013/10/07 23:58:39 SGTM. Maybe add a TODO?
nweiz 2013/10/08 00:30:39 Done, in Phase.
44 _phases.add(lastPhase);
45 for (var phase in cluster.phases.skip(1)) {
46 lastPhase = lastPhase.addPhase(phase);
47 _phases.add(lastPhase);
48 }
49
50 for (var phase in _phases) {
51 _onDirtyPool.add(phase.onDirty);
52 }
53 }
54
55 /// Adds a new asset as an input for this cluster.
56 void addInput(AssetNode node) {
57 _phases.first.addInput(node);
58 }
59
60 /// Removes this cluster and all sub-phases within it.
61 void remove() {
62 _phases.first.remove();
63 }
64
65 /// Processes this cluster.
66 ///
67 /// Returns a future that completes with any new outputs produced by the
68 /// cluster.
69 Future<Set<AssetNode>> process() {
70 for (var phase in _phases) {
Bob Nystrom 2013/10/04 21:47:50 Add comment, like "Process the first phase that ne
nweiz 2013/10/07 23:21:31 Done.
71 var future = phase.process();
72 if (future != null) return future.then((_) => process());
73 }
74
Bob Nystrom 2013/10/04 21:47:50 // If we get here, all phases are done processing.
nweiz 2013/10/07 23:21:31 Done.
75 var newOutputs = _phases.last.availableOutputs
76 .difference(_alreadyEmittedOutputs);
77 for (var output in newOutputs) {
78 output.whenRemoved.then((_) => _alreadyEmittedOutputs.remove(output));
79 }
80 _alreadyEmittedOutputs.addAll(newOutputs);
81
82 return new Future.value(newOutputs);
83 }
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698