OLD | NEW |
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.graph.phase; | 5 library barback.graph.phase; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import '../asset/asset_id.dart'; | 9 import '../asset/asset_id.dart'; |
10 import '../asset/asset_node.dart'; | 10 import '../asset/asset_node.dart'; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 /// The previous phase in the cascade, or null if this is the first phase. | 107 /// The previous phase in the cascade, or null if this is the first phase. |
108 final Phase previous; | 108 final Phase previous; |
109 | 109 |
110 /// The subscription to [previous]'s [onStatusChange] stream. | 110 /// The subscription to [previous]'s [onStatusChange] stream. |
111 StreamSubscription _previousStatusSubscription; | 111 StreamSubscription _previousStatusSubscription; |
112 | 112 |
113 /// The subscription to [previous]'s [onAsset] stream. | 113 /// The subscription to [previous]'s [onAsset] stream. |
114 StreamSubscription<AssetNode> _previousOnAssetSubscription; | 114 StreamSubscription<AssetNode> _previousOnAssetSubscription; |
115 | 115 |
| 116 final _inputSubscriptions = new Set<StreamSubscription>(); |
| 117 |
116 /// A map of asset ids to completers for [getInput] requests. | 118 /// A map of asset ids to completers for [getInput] requests. |
117 /// | 119 /// |
118 /// If an asset node is requested before it's available, we put a completer in | 120 /// If an asset node is requested before it's available, we put a completer in |
119 /// this map to wait for the asset to be generated. If it's not generated, the | 121 /// this map to wait for the asset to be generated. If it's not generated, the |
120 /// completer should complete to `null`. | 122 /// completer should complete to `null`. |
121 final _pendingOutputRequests = new Map<AssetId, Completer<AssetNode>>(); | 123 final _pendingOutputRequests = new Map<AssetId, Completer<AssetNode>>(); |
122 | 124 |
123 /// Returns all currently-available output assets for this phase. | 125 /// Returns all currently-available output assets for this phase. |
124 Set<AssetNode> get availableOutputs { | 126 Set<AssetNode> get availableOutputs { |
125 return _outputs.values | 127 return _outputs.values |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 var forwarder = new PhaseForwarder( | 172 var forwarder = new PhaseForwarder( |
171 node, _classifiers.length, _groups.length); | 173 node, _classifiers.length, _groups.length); |
172 _forwarders[node.id] = forwarder; | 174 _forwarders[node.id] = forwarder; |
173 forwarder.onAsset.listen(_handleOutputWithoutForwarder); | 175 forwarder.onAsset.listen(_handleOutputWithoutForwarder); |
174 if (forwarder.output != null) { | 176 if (forwarder.output != null) { |
175 _handleOutputWithoutForwarder(forwarder.output); | 177 _handleOutputWithoutForwarder(forwarder.output); |
176 } | 178 } |
177 | 179 |
178 _inputOrigins.add(node.origin); | 180 _inputOrigins.add(node.origin); |
179 _inputs.add(node); | 181 _inputs.add(node); |
180 node.onStateChange.listen((state) { | 182 _inputSubscriptions.add(node.onStateChange.listen((state) { |
181 if (state.isRemoved) { | 183 if (state.isRemoved) { |
182 _inputOrigins.remove(node.origin); | 184 _inputOrigins.remove(node.origin); |
183 _forwarders.remove(node.id).remove(); | 185 _forwarders.remove(node.id).remove(); |
184 } | 186 } |
185 _streams.changeStatus(status); | 187 _streams.changeStatus(status); |
186 }); | 188 })); |
187 | 189 |
188 for (var classifier in _classifiers.values) { | 190 for (var classifier in _classifiers.values) { |
189 classifier.addInput(node); | 191 classifier.addInput(node); |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 // TODO(nweiz): If the output is available when this is called, it's | 195 // TODO(nweiz): If the output is available when this is called, it's |
194 // theoretically possible for it to become unavailable between the call and | 196 // theoretically possible for it to become unavailable between the call and |
195 // the return. If it does so, it won't trigger the rebuilding process. To | 197 // the return. If it does so, it won't trigger the rebuilding process. To |
196 // avoid this, we should have this and the methods it calls take explicit | 198 // avoid this, we should have this and the methods it calls take explicit |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 /// | 319 /// |
318 /// This will remove all the phase's outputs. | 320 /// This will remove all the phase's outputs. |
319 void remove() { | 321 void remove() { |
320 for (var classifier in _classifiers.values.toList()) { | 322 for (var classifier in _classifiers.values.toList()) { |
321 classifier.remove(); | 323 classifier.remove(); |
322 } | 324 } |
323 for (var group in _groups.values) { | 325 for (var group in _groups.values) { |
324 group.remove(); | 326 group.remove(); |
325 } | 327 } |
326 _streams.close(); | 328 _streams.close(); |
| 329 for (var subscription in _inputSubscriptions) { |
| 330 subscription.cancel(); |
| 331 } |
327 if (_previousStatusSubscription != null) { | 332 if (_previousStatusSubscription != null) { |
328 _previousStatusSubscription.cancel(); | 333 _previousStatusSubscription.cancel(); |
329 } | 334 } |
330 if (_previousOnAssetSubscription != null) { | 335 if (_previousOnAssetSubscription != null) { |
331 _previousOnAssetSubscription.cancel(); | 336 _previousOnAssetSubscription.cancel(); |
332 } | 337 } |
333 } | 338 } |
334 | 339 |
335 /// Add [asset] as an output of this phase. | 340 /// Add [asset] as an output of this phase. |
336 void _handleOutput(AssetNode asset) { | 341 void _handleOutput(AssetNode asset) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 assert(asset.state.isDirty); | 387 assert(asset.state.isDirty); |
383 asset.force(); | 388 asset.force(); |
384 asset.whenStateChanges().then((state) { | 389 asset.whenStateChanges().then((state) { |
385 if (state.isRemoved) return getOutput(asset.id); | 390 if (state.isRemoved) return getOutput(asset.id); |
386 return asset; | 391 return asset; |
387 }).then(request.complete).catchError(request.completeError); | 392 }).then(request.complete).catchError(request.completeError); |
388 } | 393 } |
389 | 394 |
390 String toString() => "phase $_location.$_index"; | 395 String toString() => "phase $_location.$_index"; |
391 } | 396 } |
OLD | NEW |