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

Side by Side Diff: pkg/barback/lib/src/transformer/aggregate_transform.dart

Issue 306773002: Fix a bug where barback transformers would produce stale output. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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/CHANGELOG.md ('k') | pkg/barback/lib/src/utils/cancelable_future.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.transformer.aggregate_transform; 5 library barback.transformer.aggregate_transform;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import '../asset/asset.dart'; 10 import '../asset/asset.dart';
(...skipping 22 matching lines...) Expand all
33 /// 33 ///
34 /// This is exposed as a stream so that the transformer can start working 34 /// This is exposed as a stream so that the transformer can start working
35 /// before all its inputs are available. The stream is closed not just when 35 /// before all its inputs are available. The stream is closed not just when
36 /// all inputs are provided, but when barback is confident no more inputs will 36 /// all inputs are provided, but when barback is confident no more inputs will
37 /// be forthcoming. 37 /// be forthcoming.
38 /// 38 ///
39 /// A transformer may complete its `apply` method before this stream is 39 /// A transformer may complete its `apply` method before this stream is
40 /// closed. For example, it may know that each key will only have two inputs 40 /// closed. For example, it may know that each key will only have two inputs
41 /// associated with it, and so use `transform.primaryInputs.take(2)` to access 41 /// associated with it, and so use `transform.primaryInputs.take(2)` to access
42 /// only those inputs. 42 /// only those inputs.
43 Stream<Asset> get primaryInputs => _primaryInputs; 43 Stream<Asset> get primaryInputs => _inputController.stream;
44 Stream<Asset> _primaryInputs; 44 final _inputController = new StreamController<Asset>();
45
46 /// The controller for [primaryInputs].
47 ///
48 /// This is a broadcast controller so that the transform can keep
49 /// [_emittedPrimaryInputs] up to date.
50 final _inputController = new StreamController<Asset>.broadcast();
51 45
52 /// The set of all primary inputs that have been emitted by [primaryInputs]. 46 /// The set of all primary inputs that have been emitted by [primaryInputs].
47 ///
48 /// This is populated by the transform's controller so that
49 /// [AggregateTransformController.addedId] synchronously returns the correct
50 /// result after [AggregateTransformController.addInput] is called.
53 final _emittedPrimaryInputs = new AssetSet(); 51 final _emittedPrimaryInputs = new AssetSet();
54 52
55 AggregateTransform._(TransformNode node) 53 AggregateTransform._(TransformNode node)
56 : _node = node, 54 : _node = node,
57 super(node) { 55 super(node);
58 _inputController.stream.listen(_emittedPrimaryInputs.add);
59 // [primaryInputs] should be a non-broadcast stream.
60 _primaryInputs = broadcastToSingleSubscription(_inputController.stream);
61 }
62 56
63 /// Gets the asset for an input [id]. 57 /// Gets the asset for an input [id].
64 /// 58 ///
65 /// If an input with [id] cannot be found, throws an [AssetNotFoundException]. 59 /// If an input with [id] cannot be found, throws an [AssetNotFoundException].
66 Future<Asset> getInput(AssetId id) { 60 Future<Asset> getInput(AssetId id) {
67 if (_emittedPrimaryInputs.containsId(id)) { 61 if (_emittedPrimaryInputs.containsId(id)) {
68 return syncFuture(() => _emittedPrimaryInputs[id]); 62 return syncFuture(() => _emittedPrimaryInputs[id]);
69 } else { 63 } else {
70 return _node.getInput(id); 64 return _node.getInput(id);
71 } 65 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 /// The set of assets that the transformer has emitted. 126 /// The set of assets that the transformer has emitted.
133 AssetSet get outputs => transform._outputs; 127 AssetSet get outputs => transform._outputs;
134 128
135 bool get isDone => transform._inputController.isClosed; 129 bool get isDone => transform._inputController.isClosed;
136 130
137 AggregateTransformController(TransformNode node) 131 AggregateTransformController(TransformNode node)
138 : super(new AggregateTransform._(node)); 132 : super(new AggregateTransform._(node));
139 133
140 /// Adds a primary input asset to the [AggregateTransform.primaryInputs] 134 /// Adds a primary input asset to the [AggregateTransform.primaryInputs]
141 /// stream. 135 /// stream.
142 void addInput(Asset input) => transform._inputController.add(input); 136 void addInput(Asset input) {
137 transform._emittedPrimaryInputs.add(input);
138 transform._inputController.add(input);
139 }
143 140
144 /// Returns whether an input with the given [id] was added via [addInput]. 141 /// Returns whether an input with the given [id] was added via [addInput].
145 bool addedId(AssetId id) { 142 bool addedId(AssetId id) =>
146 return transform._emittedPrimaryInputs.ids.contains(id); 143 transform._emittedPrimaryInputs.containsId(id);
147 }
148 144
149 void done() { 145 void done() {
150 transform._inputController.close(); 146 transform._inputController.close();
151 } 147 }
152 } 148 }
OLDNEW
« no previous file with comments | « pkg/barback/CHANGELOG.md ('k') | pkg/barback/lib/src/utils/cancelable_future.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698