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