chore: Add benchmark for time and storage interference (#4)

This commit is contained in:
Marcelo Mendonça Soares 2026-01-27 15:46:30 -03:00 • committed by GitHub
commit 9dd6cbea3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,39 @@
import 'dart:io';
import 'dart:isolate';
import 'package:cli_tools/src/logger/helpers/progress.dart';
Progress? _trackedAnimationInProgress;
Future<T> runWithProgress<T>(
String message,
Future<T> Function() runner, {
bool Function(T result)? validator,
bool skipProgress = false,
}) async {
if (skipProgress) {
return Isolate.run(runner);
}
_stopAnimationInProgress();
final progress = Progress(message, stdout);
_trackedAnimationInProgress = progress;
final result = await Isolate.run(runner);
_trackedAnimationInProgress = null;
if (validator?.call(result) ?? true) {
progress.complete();
} else {
progress.fail();
}
return result;
}
void _stopAnimationInProgress() {
if (_trackedAnimationInProgress != null) {
_trackedAnimationInProgress?.stopAnimation();
// Since animation modifies the current line we add a new line so that
// the next print doesn't end up on the same line.
stdout.write('\n');
}
_trackedAnimationInProgress = null;
}