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

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

Issue 26273003: Pool future creation to ensure no more than 10 ops are in flight (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: using in polymer Created 7 years, 2 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/phase.dart ('k') | pkg/barback/lib/src/utils.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 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'asset.dart'; 10 import 'asset.dart';
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 }); 176 });
177 177
178 // Don't top-level errors coming from the input processing. Any errors will 178 // Don't top-level errors coming from the input processing. Any errors will
179 // eventually be piped through [process]'s returned Future. 179 // eventually be piped through [process]'s returned Future.
180 _adjustTransformersFuture.catchError((_) {}); 180 _adjustTransformersFuture.catchError((_) {});
181 } 181 }
182 182
183 // Remove any old transforms that used to have [asset] as a primary asset but 183 // Remove any old transforms that used to have [asset] as a primary asset but
184 // no longer apply to its new contents. 184 // no longer apply to its new contents.
185 Future _removeStaleTransforms(Asset asset, Set<Transformer> transformers) { 185 Future _removeStaleTransforms(Asset asset, Set<Transformer> transformers) {
186 return Future.wait(_transforms.map((transform) { 186
187 var txCopy = _transforms.toList();
188
189 return forEachPooledFuture(txCopy, (transform) {
187 return newFuture(() { 190 return newFuture(() {
188 if (!transformers.contains(transform.transformer)) return false; 191 if (!transformers.contains(transform.transformer)) return false;
189 192
190 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to 193 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to
191 // results. 194 // results.
192 return transform.transformer.isPrimary(asset); 195 return transform.transformer.isPrimary(asset);
193 }).then((isPrimary) { 196 }).then((isPrimary) {
194 if (isPrimary) return; 197 if (isPrimary) return;
195 _transforms.remove(transform); 198 _transforms.remove(transform);
196 transform.remove(); 199 transform.remove();
197 }); 200 });
198 })); 201 });
199 } 202 }
200 203
201 // Add new transforms for transformers that consider [input]'s asset to be a 204 // Add new transforms for transformers that consider [input]'s asset to be a
202 // primary input. 205 // primary input.
203 // 206 //
204 // [oldTransformers] is the set of transformers for which there were 207 // [oldTransformers] is the set of transformers for which there were
205 // transforms that had [input] as a primary input prior to this. They don't 208 // transforms that had [input] as a primary input prior to this. They don't
206 // need to be checked, since their transforms were removed or preserved in 209 // need to be checked, since their transforms were removed or preserved in
207 // [_removeStaleTransforms]. 210 // [_removeStaleTransforms].
208 Future _addFreshTransforms(Set<Transformer> transformers, 211 Future _addFreshTransforms(Set<Transformer> transformers,
209 Set<Transformer> oldTransformers) { 212 Set<Transformer> oldTransformers) {
210 return Future.wait(transformers.map((transformer) { 213
211 if (oldTransformers.contains(transformer)) return new Future.value(); 214 return forEachPooledFuture(transformers.toList(), (transformer) {
215 if (oldTransformers.contains(transformer)) return null;
212 216
213 // If the asset is unavailable, the results of this [_adjustTransformers] 217 // If the asset is unavailable, the results of this [_adjustTransformers]
214 // run will be discarded, so we can just short-circuit. 218 // run will be discarded, so we can just short-circuit.
215 if (input.asset == null) return new Future.value(); 219 if (input.asset == null) return null;
216 220
217 // We can safely access [input.asset] here even though it might have 221 // We can safely access [input.asset] here even though it might have
218 // changed since (as above) if it has, [_adjustTransformers] will just be 222 // changed since (as above) if it has, [_adjustTransformers] will just be
219 // re-run. 223 // re-run.
220 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to 224 // TODO(rnystrom): Catch all errors from isPrimary() and redirect to
221 // results. 225 // results.
222 return transformer.isPrimary(input.asset).then((isPrimary) { 226 return transformer.isPrimary(input.asset).then((isPrimary) {
223 if (!isPrimary) return; 227 if (!isPrimary) return;
224 var transform = new TransformNode(_phase, transformer, input); 228 var transform = new TransformNode(_phase, transformer, input);
225 _transforms.add(transform); 229 _transforms.add(transform);
226 _onDirtyPool.add(transform.onDirty); 230 _onDirtyPool.add(transform.onDirty);
227 }); 231 });
228 })); 232 });
229 } 233 }
230 234
231 /// Adjust whether [input] is passed through the phase unmodified, based on 235 /// Adjust whether [input] is passed through the phase unmodified, based on
232 /// whether it's consumed by other transforms in this phase. 236 /// whether it's consumed by other transforms in this phase.
233 /// 237 ///
234 /// If [input] was already passed-through, this will update the passed-through 238 /// If [input] was already passed-through, this will update the passed-through
235 /// value. 239 /// value.
236 void _adjustPassThrough() { 240 void _adjustPassThrough() {
237 assert(input.state.isAvailable); 241 assert(input.state.isAvailable);
238 242
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 Future<Set<AssetNode>> _processTransforms() { 285 Future<Set<AssetNode>> _processTransforms() {
282 if (input.state.isRemoved) return new Future.value(new Set()); 286 if (input.state.isRemoved) return new Future.value(new Set());
283 287
284 if (_passThroughController != null) { 288 if (_passThroughController != null) {
285 if (!_newPassThrough) return new Future.value(new Set()); 289 if (!_newPassThrough) return new Future.value(new Set());
286 _newPassThrough = false; 290 _newPassThrough = false;
287 return new Future.value( 291 return new Future.value(
288 new Set<AssetNode>.from([_passThroughController.node])); 292 new Set<AssetNode>.from([_passThroughController.node]));
289 } 293 }
290 294
291 return Future.wait(_transforms.map((transform) { 295 var outputs = new List<Set>();
296
297 return forEachPooledFuture(_transforms.toList(), (transform) {
292 if (!transform.isDirty) return new Future.value(new Set()); 298 if (!transform.isDirty) return new Future.value(new Set());
293 return transform.apply(); 299 return transform.apply()
294 })).then((outputs) => unionAll(outputs)); 300 .then(outputs.add);
301 }).then((_) => unionAll(outputs));
295 } 302 }
296 } 303 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/phase.dart ('k') | pkg/barback/lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698