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

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

Issue 200473006: Make barback's onAsset streams broadcast rather than single-subscriber. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | « pkg/barback/lib/src/asset_cascade.dart ('k') | pkg/barback/lib/src/phase.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.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';
(...skipping 19 matching lines...) Expand all
30 bool get isDirty { 30 bool get isDirty {
31 // Just check the last phase, since it will check all the previous phases 31 // Just check the last phase, since it will check all the previous phases
32 // itself. 32 // itself.
33 return _phases.last.isDirty; 33 return _phases.last.isDirty;
34 } 34 }
35 35
36 /// A stream that emits an event whenever [this] is no longer dirty. 36 /// A stream that emits an event whenever [this] is no longer dirty.
37 /// 37 ///
38 /// This is synchronous in order to guarantee that it will emit an event as 38 /// This is synchronous in order to guarantee that it will emit an event as
39 /// soon as [isDirty] flips from `true` to `false`. 39 /// soon as [isDirty] flips from `true` to `false`.
40 Stream get onDone => _onDoneController.stream; 40 Stream get onDone => _onDone;
41 final _onDoneController = new StreamController.broadcast(sync: true); 41 Stream _onDone;
42 42
43 /// A stream that emits any new assets emitted by [this]. 43 /// A stream that emits any new assets emitted by [this].
44 /// 44 ///
45 /// Assets are emitted synchronously to ensure that any changes are thoroughly 45 /// Assets are emitted synchronously to ensure that any changes are thoroughly
46 /// propagated as soon as they occur. 46 /// propagated as soon as they occur.
47 Stream<AssetNode> get onAsset => _onAssetPool.stream; 47 Stream<AssetNode> get onAsset => _onAsset;
48 final _onAssetPool = new StreamPool<AssetNode>(); 48 Stream<AssetNode> _onAsset;
49 49
50 /// A stream that emits an event whenever any transforms in this group logs 50 /// A stream that emits an event whenever any transforms in this group logs
51 /// an entry. 51 /// an entry.
52 Stream<LogEntry> get onLog => _onLogPool.stream; 52 Stream<LogEntry> get onLog => _onLogPool.stream;
53 final _onLogPool = new StreamPool<LogEntry>.broadcast(); 53 final _onLogPool = new StreamPool<LogEntry>.broadcast();
54 54
55 GroupRunner(AssetCascade cascade, this._group, this._location) { 55 GroupRunner(AssetCascade cascade, this._group, this._location) {
56 _addPhase(new Phase(cascade, _location), _group.phases.first); 56 _addPhase(new Phase(cascade, _location), _group.phases.first);
57 for (var phase in _group.phases.skip(1)) { 57 for (var phase in _group.phases.skip(1)) {
58 _addPhase(_phases.last.addPhase(), phase); 58 _addPhase(_phases.last.addPhase(), phase);
59 } 59 }
60
61 _onAsset = _phases.last.onAsset;
62 _onDone = _phases.last.onDone;
60 } 63 }
61 64
62 /// Add a phase with [contents] to [this]'s list of phases. 65 /// Add a phase with [contents] to [this]'s list of phases.
63 /// 66 ///
64 /// [contents] should be an inner [Iterable] from a [TransformGroup.phases] 67 /// [contents] should be an inner [Iterable] from a [TransformGroup.phases]
65 /// value. 68 /// value.
66 void _addPhase(Phase phase, Iterable contents) { 69 void _addPhase(Phase phase, Iterable contents) {
67 _phases.add(phase); 70 _phases.add(phase);
68 _onAssetPool.add(phase.onAsset);
69 _onLogPool.add(phase.onLog); 71 _onLogPool.add(phase.onLog);
70 phase.onDone.listen((_) {
71 if (!isDirty) _onDoneController.add(null);
72 });
73 phase.updateTransformers(contents); 72 phase.updateTransformers(contents);
74 } 73 }
75 74
76 /// Force all [LazyTransformer]s' transforms in this group to begin producing 75 /// Force all [LazyTransformer]s' transforms in this group to begin producing
77 /// concrete assets. 76 /// concrete assets.
78 void forceAllTransforms() { 77 void forceAllTransforms() {
79 for (var phase in _phases) { 78 for (var phase in _phases) {
80 phase.forceAllTransforms(); 79 phase.forceAllTransforms();
81 } 80 }
82 } 81 }
83 82
84 /// Adds a new asset as an input for this group. 83 /// Adds a new asset as an input for this group.
85 void addInput(AssetNode node) { 84 void addInput(AssetNode node) {
86 _phases.first.addInput(node); 85 _phases.first.addInput(node);
87 } 86 }
88 87
89 /// Removes this group and all sub-phases within it. 88 /// Removes this group and all sub-phases within it.
90 void remove() { 89 void remove() {
91 _phases.first.remove(); 90 for (var phase in _phases) {
91 phase.remove();
92 }
92 } 93 }
93 94
94 String toString() => "group in phase $_location for $_group"; 95 String toString() => "group in phase $_location for $_group";
95 } 96 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/asset_cascade.dart ('k') | pkg/barback/lib/src/phase.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698