printProgessAnimation<T> function
Future<T>
printProgessAnimation<T>(
- FutureOrResultCallback<
T> workload, { - Duration? animationSpeed,
- ProgressAnimationType type = ProgressAnimationType.spinningBar,
- StringSink? output,
Write a progess animation to output
while waiting for workload
.
workload
must not write to output
, otherwise the animation will
be interrupted.
output
defaults to stdout.
Implementation
Future<T> printProgessAnimation<T>(
FutureOrResultCallback<T> workload, {
Duration? animationSpeed,
ProgressAnimationType type = ProgressAnimationType.spinningBar,
StringSink? output,
}) async {
final oSink = output ?? stdout;
final timer = switch (type) {
ProgressAnimationType.spinningBar =>
_createSpinningBarAnimation(sink: oSink, animationSpeed: animationSpeed),
ProgressAnimationType.dots =>
_createDotsAnimation(sink: oSink, animationSpeed: animationSpeed),
};
T res;
try {
res = await workload();
} finally {
timer.cancel();
}
return res;
}