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

Side by Side Diff: pkg/barback/test/transformer/mock.dart

Issue 107303004: Don't limit transformer parallelism in barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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/test/package_graph/many_parallel_transformers_test.dart ('k') | no next file » | 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.test.transformer.mock; 5 library barback.test.transformer.mock;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:barback/barback.dart'; 9 import 'package:barback/barback.dart';
10 import 'package:barback/src/utils.dart'; 10 import 'package:barback/src/utils.dart';
11 import 'package:scheduled_test/scheduled_test.dart'; 11 import 'package:scheduled_test/scheduled_test.dart';
12 12
13 /// The abstract base class for transformers used to test barback. 13 /// The abstract base class for transformers used to test barback.
14 /// 14 ///
15 /// This adds the ability to pause and resume different components of the 15 /// This adds the ability to pause and resume different components of the
16 /// transformers, and to tell whether they're running, when they start running, 16 /// transformers, and to tell whether they're running, when they start running,
17 /// and how many times they've run. 17 /// and how many times they've run.
18 /// 18 ///
19 /// Transformers extending this should override [doIsPrimary] and [doApply] 19 /// Transformers extending this should override [doIsPrimary] and [doApply]
20 /// rather than [isPrimary] and [apply], and they should use [getInput] and 20 /// rather than [isPrimary] and [apply], and they should use [getInput] and
21 /// [getPrimary] rather than [transform.getInput] and [transform.primaryInput]. 21 /// [getPrimary] rather than [transform.getInput] and [transform.primaryInput].
22 abstract class MockTransformer extends Transformer { 22 abstract class MockTransformer extends Transformer {
23 /// The number of times the transformer has been applied. 23 /// The number of times the transformer has been applied.
24 /// 24 ///
25 /// This is scheduled. The Future will complete at the point in the schedule 25 /// This is scheduled. The Future will complete at the point in the schedule
26 /// that this is called. 26 /// that this is called.
27 Future<int> get numRuns => schedule(() => _numRuns); 27 Future<int> get numRuns => schedule(() => _numRuns);
28 var _numRuns = 0; 28 var _numRuns = 0;
29 29
30 Future<int> get maxParallelRuns => schedule(() => _maxParallelRuns);
31 var _maxParallelRuns = 0;
32
33 /// The number of currently running transforms. 30 /// The number of currently running transforms.
34 int _runningTransforms = 0; 31 int _runningTransforms = 0;
35 32
36 /// A completer for pausing the transformer before it finishes running [apply] . 33 /// A completer for pausing the transformer before it finishes running [apply] .
37 Completer _apply; 34 Completer _apply;
38 35
39 /// Completers for pausing the transformer before it finishes running 36 /// Completers for pausing the transformer before it finishes running
40 /// [isPrimary]. 37 /// [isPrimary].
41 final _isPrimary = new Map<AssetId, Completer>(); 38 final _isPrimary = new Map<AssetId, Completer>();
42 39
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return _isPrimary[asset.id].future; 169 return _isPrimary[asset.id].future;
173 } 170 }
174 }).then((_) => result); 171 }).then((_) => result);
175 }); 172 });
176 } 173 }
177 174
178 Future apply(Transform transform) { 175 Future apply(Transform transform) {
179 _numRuns++; 176 _numRuns++;
180 if (_runningTransforms == 0) _started.complete(); 177 if (_runningTransforms == 0) _started.complete();
181 _runningTransforms++; 178 _runningTransforms++;
182 if (_runningTransforms > _maxParallelRuns) {
183 _maxParallelRuns = _runningTransforms;
184 }
185 return newFuture(() => doApply(transform)).then((_) { 179 return newFuture(() => doApply(transform)).then((_) {
186 if (_apply != null) return _apply.future; 180 if (_apply != null) return _apply.future;
187 }).whenComplete(() { 181 }).whenComplete(() {
188 _runningTransforms--; 182 _runningTransforms--;
189 if (_runningTransforms == 0) _started = new Completer(); 183 if (_runningTransforms == 0) _started = new Completer();
190 }); 184 });
191 } 185 }
192 186
193 /// The wrapped version of [isPrimary] for subclasses to override. 187 /// The wrapped version of [isPrimary] for subclasses to override.
194 Future<bool> doIsPrimary(Asset asset); 188 Future<bool> doIsPrimary(Asset asset);
195 189
196 /// The wrapped version of [doApply] for subclasses to override. 190 /// The wrapped version of [doApply] for subclasses to override.
197 Future doApply(Transform transform); 191 Future doApply(Transform transform);
198 } 192 }
OLDNEW
« no previous file with comments | « pkg/barback/test/package_graph/many_parallel_transformers_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698