OLD | NEW |
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.test.transformer.mock_aggregate; | 5 library barback.test.transformer.mock_aggregate; |
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'; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void resumePrimaryInputs() { | 146 void resumePrimaryInputs() { |
147 schedule(() { | 147 schedule(() { |
148 _primaryInputs.complete(); | 148 _primaryInputs.complete(); |
149 _primaryInputs = null; | 149 _primaryInputs = null; |
150 }, "resume primaryInputs for $this"); | 150 }, "resume primaryInputs for $this"); |
151 } | 151 } |
152 | 152 |
153 /// Like [AggregateTransform.getInput], but respects [pauseGetInput]. | 153 /// Like [AggregateTransform.getInput], but respects [pauseGetInput]. |
154 /// | 154 /// |
155 /// This is intended for use by subclasses of [MockAggregateTransformer]. | 155 /// This is intended for use by subclasses of [MockAggregateTransformer]. |
156 Future<Asset> getInput(AggregateTransform transform, AssetId id) { | 156 Future<Asset> getInput(AggregateTransform transform, AssetId id) async { |
157 return newFuture(() { | 157 if (_getInput.containsKey(id)) await _getInput[id].future; |
158 if (_getInput.containsKey(id)) return _getInput[id].future; | 158 return await transform.getInput(id); |
159 }).then((_) => transform.getInput(id)); | |
160 } | 159 } |
161 | 160 |
162 /// Like [AggregateTransform.primaryInputs], but respects | 161 /// Like [AggregateTransform.primaryInputs], but respects |
163 /// [pausePrimaryInputs]. | 162 /// [pausePrimaryInputs]. |
164 /// | 163 /// |
165 /// This is intended for use by subclasses of [MockAggregateTransformer]. | 164 /// This is intended for use by subclasses of [MockAggregateTransformer]. |
166 Stream<Asset> getPrimaryInputs(AggregateTransform transform) { | 165 Stream<Asset> getPrimaryInputs(AggregateTransform transform) { |
167 return futureStream(newFuture(() { | 166 return futureStream(newFuture(() { |
168 if (_primaryInputs != null) return _primaryInputs.future; | 167 if (_primaryInputs != null) return _primaryInputs.future; |
169 }).then((_) => transform.primaryInputs)); | 168 }).then((_) => transform.primaryInputs)); |
170 } | 169 } |
171 | 170 |
172 Future<String> classifyPrimary(AssetId id) { | 171 Future<String> classifyPrimary(AssetId id) async { |
173 return newFuture(() => doClassifyPrimary(id)).then((result) { | 172 var result = await doClassifyPrimary(id); |
174 return newFuture(() { | 173 if (_classifyPrimary.containsKey(id)) await _classifyPrimary[id].future; |
175 if (_classifyPrimary.containsKey(id)) { | 174 return result; |
176 return _classifyPrimary[id].future; | |
177 } | |
178 }).then((_) => result); | |
179 }); | |
180 } | 175 } |
181 | 176 |
182 Future apply(AggregateTransform transform) { | 177 Future apply(AggregateTransform transform) { |
183 _numRuns++; | 178 _numRuns++; |
184 if (_runningTransforms == 0) _started.complete(); | 179 if (_runningTransforms == 0) _started.complete(); |
185 _runningTransforms++; | 180 _runningTransforms++; |
186 return newFuture(() => doApply(transform)).then((_) { | 181 return newFuture(() => doApply(transform)).then((_) { |
187 if (_apply != null) return _apply.future; | 182 if (_apply != null) return _apply.future; |
188 }).whenComplete(() { | 183 }).whenComplete(() { |
189 for (var id in consumePrimaries) { | 184 for (var id in consumePrimaries) { |
190 transform.consumePrimary(new AssetId.parse(id)); | 185 transform.consumePrimary(new AssetId.parse(id)); |
191 } | 186 } |
192 _runningTransforms--; | 187 _runningTransforms--; |
193 if (_runningTransforms == 0) _started = new Completer(); | 188 if (_runningTransforms == 0) _started = new Completer(); |
194 }); | 189 }); |
195 } | 190 } |
196 | 191 |
197 /// The wrapped version of [classifyPrimary] for subclasses to override. | 192 /// The wrapped version of [classifyPrimary] for subclasses to override. |
198 /// | 193 /// |
199 /// This may return a `Future<String>` or, if it's entirely synchronous, a | 194 /// This may return a `Future<String>` or, if it's entirely synchronous, a |
200 /// `String`. | 195 /// `String`. |
201 doClassifyPrimary(AssetId id); | 196 doClassifyPrimary(AssetId id); |
202 | 197 |
203 /// The wrapped version of [doApply] for subclasses to override. | 198 /// The wrapped version of [doApply] for subclasses to override. |
204 /// | 199 /// |
205 /// If this does asynchronous work, it should return a [Future] that completes | 200 /// If this does asynchronous work, it should return a [Future] that completes |
206 /// once it's finished. | 201 /// once it's finished. |
207 doApply(AggregateTransform transform); | 202 doApply(AggregateTransform transform); |
208 } | 203 } |
OLD | NEW |