runSpinnerTask<T> function
Future<T>
runSpinnerTask<T>({
- required String message,
- required Future<
T> task(), - Spinner spinner = Spinners.miniDot,
- required Terminal terminal,
- ProgramOptions? options,
Runs an animated spinner while executing task, returning its result.
Implementation
Future<T> runSpinnerTask<T>({
required String message,
required Future<T> Function() task,
Spinner spinner = Spinners.miniDot,
required Terminal terminal,
ProgramOptions? options,
}) async {
final controller = _PromptController<T>();
// Pre-attach an error listener so that if [_SpinnerTaskModel] calls
// [completeError] while the program is still running (e.g. on InterruptMsg),
// Dart's async machinery does not flag the future as an unhandled error
// before [program.run()] returns and we reach the `await controller.future`
// below. The separate listener does NOT swallow the error — the `await`
// below will still throw as expected.
final resultFuture = controller.future
..ignore(); // registers a no-op error listener; original future is intact
final program = Program(
_SpinnerTaskModel<T>(
message: message,
task: task,
spinner: spinner,
controller: controller,
),
options: options ?? promptProgramOptions,
terminal: terminal,
);
await program.run();
return await resultFuture;
}