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

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

Issue 26572010: Improve barback/pub logging. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing file. 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
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 'barback_logger.dart';
11 import 'phase.dart'; 12 import 'phase.dart';
12 import 'stream_pool.dart'; 13 import 'stream_pool.dart';
13 import 'transformer_group.dart'; 14 import 'transformer_group.dart';
14 15
15 /// A class that process all of the phases in a single transformer group. 16 /// A class that process all of the phases in a single transformer group.
16 /// 17 ///
17 /// A group takes many inputs, processes them, and emits many outputs. 18 /// A group takes many inputs, processes them, and emits many outputs.
18 class GroupRunner { 19 class GroupRunner {
19 /// The phases defined by this group. 20 /// The phases defined by this group.
20 final _phases = new List<Phase>(); 21 final _phases = new List<Phase>();
21 22
22 /// A stream that emits an event whenever this group becomes dirty and needs 23 /// A stream that emits an event whenever this group becomes dirty and needs
23 /// to be run. 24 /// to be run.
24 /// 25 ///
25 /// This may emit events when the group was already dirty or while processing 26 /// This may emit events when the group was already dirty or while processing
26 /// transforms. Events are emitted synchronously to ensure that the dirty 27 /// transforms. Events are emitted synchronously to ensure that the dirty
27 /// state is thoroughly propagated as soon as any assets are changed. 28 /// state is thoroughly propagated as soon as any assets are changed.
28 Stream get onDirty => _onDirtyPool.stream; 29 Stream get onDirty => _onDirtyPool.stream;
29 final _onDirtyPool = new StreamPool.broadcast(); 30 final _onDirtyPool = new StreamPool.broadcast();
30 31
31 /// Whether this group is dirty and needs to be run. 32 /// Whether this group is dirty and needs to be run.
32 bool get isDirty => _phases.any((phase) => phase.isDirty); 33 bool get isDirty => _phases.any((phase) => phase.isDirty);
33 34
35 /// A stream that emits an event whenever any transforms in this group log an
nweiz 2013/10/16 19:41:27 "log" -> "logs"
Bob Nystrom 2013/10/28 23:45:56 Done.
36 /// entry.
37 Stream<LogEntry> get onLog => _onLogPool.stream;
38 final _onLogPool = new StreamPool<LogEntry>.broadcast();
39
34 // TODO(nweiz): move to a more push-based way of propagating outputs and get 40 // TODO(nweiz): move to a more push-based way of propagating outputs and get
35 // rid of this. Once that's done, see if we can unify GroupRunner and 41 // rid of this. Once that's done, see if we can unify GroupRunner and
36 // AssetCascade. 42 // AssetCascade.
37 /// The set of outputs that has been returned by [process]. 43 /// The set of outputs that has been returned by [process].
38 /// 44 ///
39 /// [process] is expected to only return new outputs, so this is used to 45 /// [process] is expected to only return new outputs, so this is used to
40 /// ensure that it does so. 46 /// ensure that it does so.
41 final _alreadyEmittedOutputs = new Set<AssetNode>(); 47 final _alreadyEmittedOutputs = new Set<AssetNode>();
42 48
43 GroupRunner(AssetCascade cascade, TransformerGroup group) { 49 GroupRunner(AssetCascade cascade, TransformerGroup group) {
44 var lastPhase = new Phase(cascade, group.phases.first); 50 var lastPhase = new Phase(cascade, group.phases.first);
45 _phases.add(lastPhase); 51 _phases.add(lastPhase);
46 for (var phase in group.phases.skip(1)) { 52 for (var phase in group.phases.skip(1)) {
47 lastPhase = lastPhase.addPhase(phase); 53 lastPhase = lastPhase.addPhase(phase);
48 _phases.add(lastPhase); 54 _phases.add(lastPhase);
49 } 55 }
50 56
51 for (var phase in _phases) { 57 for (var phase in _phases) {
52 _onDirtyPool.add(phase.onDirty); 58 _onDirtyPool.add(phase.onDirty);
59 _onLogPool.add(phase.onLog);
53 } 60 }
54 } 61 }
55 62
56 /// Adds a new asset as an input for this group. 63 /// Adds a new asset as an input for this group.
57 void addInput(AssetNode node) { 64 void addInput(AssetNode node) {
58 _phases.first.addInput(node); 65 _phases.first.addInput(node);
59 } 66 }
60 67
61 /// Removes this group and all sub-phases within it. 68 /// Removes this group and all sub-phases within it.
62 void remove() { 69 void remove() {
(...skipping 15 matching lines...) Expand all
78 var newOutputs = _phases.last.availableOutputs 85 var newOutputs = _phases.last.availableOutputs
79 .difference(_alreadyEmittedOutputs); 86 .difference(_alreadyEmittedOutputs);
80 for (var output in newOutputs) { 87 for (var output in newOutputs) {
81 output.whenRemoved.then((_) => _alreadyEmittedOutputs.remove(output)); 88 output.whenRemoved.then((_) => _alreadyEmittedOutputs.remove(output));
82 } 89 }
83 _alreadyEmittedOutputs.addAll(newOutputs); 90 _alreadyEmittedOutputs.addAll(newOutputs);
84 91
85 return new Future.value(newOutputs); 92 return new Future.value(newOutputs);
86 } 93 }
87 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698