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

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

Issue 238503003: Make [Barback.getAllAssets] work when called synchronously. (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/test/package_graph/get_all_assets_test.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.phase_input; 5 library barback.phase_input;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'asset_forwarder.dart'; 9 import 'asset_forwarder.dart';
10 import 'asset_node.dart'; 10 import 'asset_node.dart';
(...skipping 20 matching lines...) Expand all
31 final _transforms = new Set<TransformNode>(); 31 final _transforms = new Set<TransformNode>();
32 32
33 /// A forwarder for the input [AssetNode] for this phase. 33 /// A forwarder for the input [AssetNode] for this phase.
34 /// 34 ///
35 /// This is used to mark the node as removed should the input ever be removed. 35 /// This is used to mark the node as removed should the input ever be removed.
36 final AssetForwarder _inputForwarder; 36 final AssetForwarder _inputForwarder;
37 37
38 /// The asset node for this input. 38 /// The asset node for this input.
39 AssetNode get input => _inputForwarder.node; 39 AssetNode get input => _inputForwarder.node;
40 40
41 /// The subscription to [input]'s [AssetNode.onStateChange] stream.
42 StreamSubscription _inputSubscription;
43
41 /// A stream that emits an event whenever [this] is no longer dirty. 44 /// A stream that emits an event whenever [this] is no longer dirty.
42 /// 45 ///
43 /// This is synchronous in order to guarantee that it will emit an event as 46 /// This is synchronous in order to guarantee that it will emit an event as
44 /// soon as [isDirty] flips from `true` to `false`. 47 /// soon as [isDirty] flips from `true` to `false`.
45 Stream get onDone => _onDoneController.stream; 48 Stream get onDone => _onDoneController.stream;
46 final _onDoneController = new StreamController.broadcast(sync: true); 49 final _onDoneController = new StreamController.broadcast(sync: true);
47 50
48 /// A stream that emits any new assets emitted by [this]. 51 /// A stream that emits any new assets emitted by [this].
49 /// 52 ///
50 /// Assets are emitted synchronously to ensure that any changes are thoroughly 53 /// Assets are emitted synchronously to ensure that any changes are thoroughly
51 /// propagated as soon as they occur. 54 /// propagated as soon as they occur.
52 Stream<AssetNode> get onAsset => _onAssetPool.stream; 55 Stream<AssetNode> get onAsset => _onAssetPool.stream;
53 final _onAssetPool = new StreamPool<AssetNode>.broadcast(); 56 final _onAssetPool = new StreamPool<AssetNode>.broadcast();
54 57
55 /// Whether [this] is dirty and still has more processing to do. 58 /// Whether [this] is dirty and still has more processing to do.
56 bool get isDirty => _transforms.any((transform) => transform.isDirty); 59 bool get isDirty => (input.state.isDirty && !input.deferred) ||
60 _transforms.any((transform) => transform.isDirty);
57 61
58 /// A stream that emits an event whenever any transforms that use [input] as 62 /// A stream that emits an event whenever any transforms that use [input] as
59 /// their primary input log an entry. 63 /// their primary input log an entry.
60 Stream<LogEntry> get onLog => _onLogPool.stream; 64 Stream<LogEntry> get onLog => _onLogPool.stream;
61 final _onLogPool = new StreamPool<LogEntry>.broadcast(); 65 final _onLogPool = new StreamPool<LogEntry>.broadcast();
62 66
63 PhaseInput(this._phase, AssetNode input, this._location) 67 PhaseInput(this._phase, AssetNode input, this._location)
64 : _inputForwarder = new AssetForwarder(input) { 68 : _inputForwarder = new AssetForwarder(input) {
65 input.whenRemoved(remove); 69 _inputSubscription = input.onStateChange.listen((state) {
70 if (state.isRemoved) {
71 remove();
72 } else if (state.isAvailable) {
73 if (!isDirty) _onDoneController.add(null);
74 }
75 });
66 } 76 }
67 77
68 /// Removes this input. 78 /// Removes this input.
69 /// 79 ///
70 /// This marks all outputs of the input as removed. 80 /// This marks all outputs of the input as removed.
71 void remove() { 81 void remove() {
82 _inputSubscription.cancel();
72 _onDoneController.close(); 83 _onDoneController.close();
73 _onAssetPool.close(); 84 _onAssetPool.close();
74 _onLogPool.close(); 85 _onLogPool.close();
75 _inputForwarder.close(); 86 _inputForwarder.close();
76 } 87 }
77 88
78 /// Set this input's transformers to [transformers]. 89 /// Set this input's transformers to [transformers].
79 void updateTransformers(Iterable<Transformer> newTransformersIterable) { 90 void updateTransformers(Iterable<Transformer> newTransformersIterable) {
80 var newTransformers = newTransformersIterable.toSet(); 91 var newTransformers = newTransformersIterable.toSet();
81 for (var transform in _transforms.toList()) { 92 for (var transform in _transforms.toList()) {
(...skipping 20 matching lines...) Expand all
102 /// Force all [LazyTransformer]s' transforms in this input to begin producing 113 /// Force all [LazyTransformer]s' transforms in this input to begin producing
103 /// concrete assets. 114 /// concrete assets.
104 void forceAllTransforms() { 115 void forceAllTransforms() {
105 for (var transform in _transforms) { 116 for (var transform in _transforms) {
106 transform.force(); 117 transform.force();
107 } 118 }
108 } 119 }
109 120
110 String toString() => "phase input in $_location for $input"; 121 String toString() => "phase input in $_location for $input";
111 } 122 }
OLDNEW
« no previous file with comments | « no previous file | pkg/barback/test/package_graph/get_all_assets_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698