progress_future 0.1.0 progress_future: ^0.1.0 copied to clipboard
A Future that reports the progress of its completion, and various progress bars to show it in CLI.
import 'package:progress_future/progress_future.dart';
Future<void> main() async {
// Integer progress:
final future = wait(5);
future.events.listen((event) {
print('${event.progress} seconds elapsed.');
});
print(await future);
}
IntProgressFuture<String> wait(int seconds) {
final updater = IntProgressUpdater(total: seconds);
Future<String> generate(int seconds) async {
for (int n = 0; n < seconds; n++) {
updater.setProgress(n);
await Future.delayed(const Duration(seconds: 1));
}
return 'Waited $seconds seconds.';
}
return IntProgressFuture.wrap(generate(seconds), updater);
}