| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 /// Once this transformer finishes running, this is reset to a new completer, | 49 /// Once this transformer finishes running, this is reset to a new completer, |
| 50 /// so it can be used multiple times. | 50 /// so it can be used multiple times. |
| 51 var _started = new Completer(); | 51 var _started = new Completer(); |
| 52 | 52 |
| 53 /// `true` if any transforms are currently running. | 53 /// `true` if any transforms are currently running. |
| 54 /// | 54 /// |
| 55 /// This is scheduled. The Future will complete at the point in the schedule | 55 /// This is scheduled. The Future will complete at the point in the schedule |
| 56 /// that this is called. | 56 /// that this is called. |
| 57 Future<bool> get isRunning => schedule(() => _runningTransforms > 0); | 57 Future<bool> get isRunning => schedule(() => _runningTransforms > 0); |
| 58 | 58 |
| 59 /// If this is set to `true`, the transformer will consume its primary input |
| 60 /// during [apply]. |
| 61 bool consumePrimary = false; |
| 62 |
| 59 /// Pauses the schedule until this transformer begins running. | 63 /// Pauses the schedule until this transformer begins running. |
| 60 void waitUntilStarted() { | 64 void waitUntilStarted() { |
| 61 schedule(() => _started.future, "wait until $this starts"); | 65 schedule(() => _started.future, "wait until $this starts"); |
| 62 } | 66 } |
| 63 | 67 |
| 64 /// Causes the transformer to pause after running [apply] but before the | 68 /// Causes the transformer to pause after running [apply] but before the |
| 65 /// returned Future completes. | 69 /// returned Future completes. |
| 66 /// | 70 /// |
| 67 /// This can be resumed by calling [resumeApply]. This operation is scheduled. | 71 /// This can be resumed by calling [resumeApply]. This operation is scheduled. |
| 68 void pauseApply() { | 72 void pauseApply() { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 return _isPrimary[asset.id].future; | 173 return _isPrimary[asset.id].future; |
| 170 } | 174 } |
| 171 }).then((_) => result); | 175 }).then((_) => result); |
| 172 }); | 176 }); |
| 173 } | 177 } |
| 174 | 178 |
| 175 Future apply(Transform transform) { | 179 Future apply(Transform transform) { |
| 176 _numRuns++; | 180 _numRuns++; |
| 177 if (_runningTransforms == 0) _started.complete(); | 181 if (_runningTransforms == 0) _started.complete(); |
| 178 _runningTransforms++; | 182 _runningTransforms++; |
| 183 if (consumePrimary) transform.consumePrimary(); |
| 179 return newFuture(() => doApply(transform)).then((_) { | 184 return newFuture(() => doApply(transform)).then((_) { |
| 180 if (_apply != null) return _apply.future; | 185 if (_apply != null) return _apply.future; |
| 181 }).whenComplete(() { | 186 }).whenComplete(() { |
| 182 _runningTransforms--; | 187 _runningTransforms--; |
| 183 if (_runningTransforms == 0) _started = new Completer(); | 188 if (_runningTransforms == 0) _started = new Completer(); |
| 184 }); | 189 }); |
| 185 } | 190 } |
| 186 | 191 |
| 187 /// The wrapped version of [isPrimary] for subclasses to override. | 192 /// The wrapped version of [isPrimary] for subclasses to override. |
| 188 Future<bool> doIsPrimary(Asset asset); | 193 Future<bool> doIsPrimary(Asset asset); |
| 189 | 194 |
| 190 /// The wrapped version of [doApply] for subclasses to override. | 195 /// The wrapped version of [doApply] for subclasses to override. |
| 191 Future doApply(Transform transform); | 196 Future doApply(Transform transform); |
| 192 } | 197 } |
| OLD | NEW |