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

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

Issue 249183005: Move common streams in barback to their own class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | pkg/barback/lib/src/group_runner.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.asset_cascade; 5 library barback.asset_cascade;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset.dart'; 9 import 'asset.dart';
10 import 'asset_id.dart'; 10 import 'asset_id.dart';
11 import 'asset_node.dart'; 11 import 'asset_node.dart';
12 import 'asset_set.dart'; 12 import 'asset_set.dart';
13 import 'log.dart'; 13 import 'log.dart';
14 import 'cancelable_future.dart'; 14 import 'cancelable_future.dart';
15 import 'errors.dart'; 15 import 'errors.dart';
16 import 'node_streams.dart';
16 import 'package_graph.dart'; 17 import 'package_graph.dart';
17 import 'phase.dart'; 18 import 'phase.dart';
18 import 'stream_pool.dart';
19 import 'transformer.dart'; 19 import 'transformer.dart';
20 20
21 /// The asset cascade for an individual package. 21 /// The asset cascade for an individual package.
22 /// 22 ///
23 /// This keeps track of which [Transformer]s are applied to which assets, and 23 /// This keeps track of which [Transformer]s are applied to which assets, and
24 /// re-runs those transformers when their dependencies change. The transformed 24 /// re-runs those transformers when their dependencies change. The transformed
25 /// asset nodes are accessible via [getAssetNode]. 25 /// asset nodes are accessible via [getAssetNode].
26 /// 26 ///
27 /// A cascade consists of one or more [Phases], each of which has one or more 27 /// A cascade consists of one or more [Phases], each of which has one or more
28 /// [Transformer]s that run in parallel, potentially on the same inputs. The 28 /// [Transformer]s that run in parallel, potentially on the same inputs. The
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 StreamSubscription _phaseOnDoneSubscription; 60 StreamSubscription _phaseOnDoneSubscription;
61 61
62 /// A stream that emits any errors from the cascade or the transformers. 62 /// A stream that emits any errors from the cascade or the transformers.
63 /// 63 ///
64 /// This emits errors as they're detected. If an error occurs in one part of 64 /// This emits errors as they're detected. If an error occurs in one part of
65 /// the cascade, unrelated parts will continue building. 65 /// the cascade, unrelated parts will continue building.
66 Stream<BarbackException> get errors => _errorsController.stream; 66 Stream<BarbackException> get errors => _errorsController.stream;
67 final _errorsController = 67 final _errorsController =
68 new StreamController<BarbackException>.broadcast(sync: true); 68 new StreamController<BarbackException>.broadcast(sync: true);
69 69
70 /// A stream that emits an event whenever any transforms in this cascade logs
71 /// an entry.
72 Stream<LogEntry> get onLog => _onLogPool.stream;
73 final _onLogPool = new StreamPool<LogEntry>.broadcast();
74
75 /// Whether [this] is dirty and still has more processing to do. 70 /// Whether [this] is dirty and still has more processing to do.
76 bool get isDirty { 71 bool get isDirty {
77 // Just check the last phase, since it will check all the previous phases 72 // Just check the last phase, since it will check all the previous phases
78 // itself. 73 // itself.
79 return _phases.last.isDirty; 74 return _phases.last.isDirty;
80 } 75 }
81 76
82 /// A stream that emits an event whenever [this] is no longer dirty. 77 /// The streams exposed by this cascade.
83 /// 78 final _streams = new NodeStreams();
84 /// This is synchronous in order to guarantee that it will emit an event as 79 Stream<LogEntry> get onLog => _streams.onLog;
85 /// soon as [isDirty] flips from `true` to `false`. 80 Stream get onDone => _streams.onDone;
86 Stream get onDone => _onDoneController.stream;
87 final _onDoneController = new StreamController.broadcast(sync: true);
88 81
89 /// Returns all currently-available output assets from this cascade. 82 /// Returns all currently-available output assets from this cascade.
90 AssetSet get availableOutputs => 83 AssetSet get availableOutputs =>
91 new AssetSet.from(_phases.last.availableOutputs.map((node) => node.asset)); 84 new AssetSet.from(_phases.last.availableOutputs.map((node) => node.asset));
92 85
93 /// Creates a new [AssetCascade]. 86 /// Creates a new [AssetCascade].
94 /// 87 ///
95 /// It loads source assets within [package] using [provider]. 88 /// It loads source assets within [package] using [provider].
96 AssetCascade(this.graph, this.package) { 89 AssetCascade(this.graph, this.package) {
97 _addPhase(new Phase(this, package)); 90 _addPhase(new Phase(this, package));
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 phase.updateTransformers(transformers[i]); 185 phase.updateTransformers(transformers[i]);
193 } 186 }
194 187
195 for (var i = transformers.length + 1; i < _phases.length; i++) { 188 for (var i = transformers.length + 1; i < _phases.length; i++) {
196 _phases[i].remove(); 189 _phases[i].remove();
197 } 190 }
198 _phases.removeRange(transformers.length + 1, _phases.length); 191 _phases.removeRange(transformers.length + 1, _phases.length);
199 192
200 _phaseOnDoneSubscription.cancel(); 193 _phaseOnDoneSubscription.cancel();
201 _phaseOnDoneSubscription = _phases.last.onDone 194 _phaseOnDoneSubscription = _phases.last.onDone
202 .listen(_onDoneController.add); 195 .listen(_streams.onDoneController.add);
203 } 196 }
204 197
205 /// Force all [LazyTransformer]s' transforms in this cascade to begin 198 /// Force all [LazyTransformer]s' transforms in this cascade to begin
206 /// producing concrete assets. 199 /// producing concrete assets.
207 void forceAllTransforms() { 200 void forceAllTransforms() {
208 for (var phase in _phases) { 201 for (var phase in _phases) {
209 phase.forceAllTransforms(); 202 phase.forceAllTransforms();
210 } 203 }
211 } 204 }
212 205
213 void reportError(BarbackException error) { 206 void reportError(BarbackException error) {
214 _errorsController.add(error); 207 _errorsController.add(error);
215 } 208 }
216 209
217 /// Add [phase] to the end of [_phases] and watch its streams. 210 /// Add [phase] to the end of [_phases] and watch its streams.
218 void _addPhase(Phase phase) { 211 void _addPhase(Phase phase) {
219 _onLogPool.add(phase.onLog); 212 _streams.onLogPool.add(phase.onLog);
220 if (_phaseOnDoneSubscription != null) _phaseOnDoneSubscription.cancel(); 213 if (_phaseOnDoneSubscription != null) _phaseOnDoneSubscription.cancel();
221 _phaseOnDoneSubscription = phase.onDone.listen(_onDoneController.add); 214 _phaseOnDoneSubscription =
215 phase.onDone.listen(_streams.onDoneController.add);
222 216
223 _phases.add(phase); 217 _phases.add(phase);
224 } 218 }
225 219
226 String toString() => "cascade for $package"; 220 String toString() => "cascade for $package";
227 } 221 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/lib/src/group_runner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698