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

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

Issue 188673004: Roll forward commits r33138, r33135, and r33134. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-upload 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
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.phase_forwarder; 5 library barback.phase_forwarder;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset_node.dart'; 9 import 'asset_node.dart';
10 import 'asset_node_set.dart';
10 11
11 /// A class that takes care of forwarding assets within a phase. 12 /// A class that takes care of forwarding assets within a phase.
12 /// 13 ///
13 /// Each phase contains one or more channels that process its input assets. The 14 /// Each phase contains one or more channels that process its input assets. The
14 /// non-grouped transformers for that phase are one such channel, and each 15 /// non-grouped transformers for that phase are one such channel, and each
15 /// [TransformerGroup] in that phase is another. For each input asset, each 16 /// [TransformerGroup] in that phase is another. For each input asset, each
16 /// channel individually decides whether to forward that asset based on whether 17 /// channel individually decides whether to forward that asset based on whether
17 /// that channel uses it. If a channel does decide to forward an asset, we call 18 /// that channel uses it. If a channel does decide to forward an asset, we call
18 /// that forwarded asset an "intermediate forwarded asset" to distinguish it 19 /// that forwarded asset an "intermediate forwarded asset" to distinguish it
19 /// from the output of a [PhaseForwarder]. 20 /// from the output of a [PhaseForwarder].
(...skipping 13 matching lines...) Expand all
33 /// 34 ///
34 /// Each group is a channel, along with one channel for the [PhaseInput] that 35 /// Each group is a channel, along with one channel for the [PhaseInput] that
35 /// handles all the transformers. 36 /// handles all the transformers.
36 set numChannels(int value) { 37 set numChannels(int value) {
37 _numChannels = value; 38 _numChannels = value;
38 _adjustOutput(); 39 _adjustOutput();
39 } 40 }
40 int _numChannels; 41 int _numChannels;
41 42
42 /// The intermediate forwarded assets. 43 /// The intermediate forwarded assets.
43 final _intermediateAssets = new Set<AssetNode>(); 44 final _intermediateAssets = new AssetNodeSet();
44 45
45 /// The final forwarded asset. 46 /// The final forwarded asset.
46 /// 47 ///
47 /// This will be null if the asset is not being forwarded. 48 /// This will be null if the asset is not being forwarded.
48 AssetNode get output => _outputController.node; 49 AssetNode get output => _outputController.node;
49 AssetNodeController _outputController; 50 AssetNodeController _outputController;
50 51
51 /// A stream that emits an event whenever [this] starts producing a final 52 /// A stream that emits an event whenever [this] starts producing a final
52 /// forwarded asset. 53 /// forwarded asset.
53 /// 54 ///
54 /// Whenever this stream emits an event, the value will be identical to 55 /// Whenever this stream emits an event, the value will be identical to
55 /// [output]. 56 /// [output].
56 Stream<AssetNode> get onAsset => _onAssetController.stream; 57 Stream<AssetNode> get onAsset => _onAssetController.stream;
57 final _onAssetController = new StreamController<AssetNode>(sync: true); 58 final _onAssetController = new StreamController<AssetNode>(sync: true);
58 59
59 PhaseForwarder(this._numChannels); 60 PhaseForwarder(this._numChannels);
60 61
61 /// Adds an intermediate forwarded asset to [this]. 62 /// Adds an intermediate forwarded asset to [this].
62 /// 63 ///
63 /// [asset] must have the same origin as all other intermediate forwarded 64 /// [asset] must have the same origin as all other intermediate forwarded
64 /// assets. 65 /// assets.
65 void addIntermediateAsset(AssetNode asset) { 66 void addIntermediateAsset(AssetNode asset) {
66 if (_intermediateAssets.isNotEmpty) { 67 if (_intermediateAssets.isNotEmpty) {
67 assert(asset.origin == _intermediateAssets.first.origin); 68 assert(asset.origin == _intermediateAssets.first.origin);
68 } 69 }
69 70
70 _intermediateAssets.add(asset); 71 _intermediateAssets.add(asset);
71 72 asset.onStateChange.listen((_) => _adjustOutput());
72 asset.onStateChange.listen((state) {
73 if (state.isRemoved) _intermediateAssets.remove(asset);
74 _adjustOutput();
75 });
76 73
77 _adjustOutput(); 74 _adjustOutput();
78 } 75 }
79 76
80 /// Mark this forwarder as removed. 77 /// Mark this forwarder as removed.
81 /// 78 ///
82 /// This will remove [output] if it exists. 79 /// This will remove [output] if it exists.
83 void remove() { 80 void remove() {
84 if (_outputController != null) { 81 if (_outputController != null) {
85 _outputController.setRemoved(); 82 _outputController.setRemoved();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // intermediate assets are dirty. 116 // intermediate assets are dirty.
120 if (_intermediateAssets.any((asset) => asset.state.isDirty)) { 117 if (_intermediateAssets.any((asset) => asset.state.isDirty)) {
121 if (!_outputController.node.state.isDirty) _outputController.setDirty(); 118 if (!_outputController.node.state.isDirty) _outputController.setDirty();
122 } else { 119 } else {
123 if (!_outputController.node.state.isAvailable) { 120 if (!_outputController.node.state.isAvailable) {
124 _outputController.setAvailable(_intermediateAssets.first.asset); 121 _outputController.setAvailable(_intermediateAssets.first.asset);
125 } 122 }
126 } 123 }
127 } 124 }
128 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698