10.16. Progress Indicators
As annoying as it is to sit like a mushroom whilst some mute program waits for your unprompted input, it's even more frustrating to tentatively start typing something into an interactive program, only to discover that the program is still busy initializing, or calculating, or connecting to a remote device: # Initialize from any config files... for my $possible_config ( @CONFIG_PATHS ) { init_from($possible_config); } # Connect to remote server... my $connection; TRY: for my $try (1..$MAX_TRIES) { # Retry connection with increasingly tolerant timeout intervals... $connection = connect_to($REMOTE_SERVER, { timeout => fibonacci($try) }); last TRY if $connection; } croak "Can't contact server ($REMOTE_SERVER)" if !$connection; # Interactive portion of the program starts here... while (my $cmd = prompt($prompt_str, -fail_if=>$QUIT)) { remote_execute($connection, $cmd) or carp "Unknown command: $cmd"; }It's much betterand not much more onerousto give an active indication that an interactive program is busy doing something non-interactive: Better still, factor those messages out into a set of utility subroutines: Note that some of the comments have been dispensed with, as the _begin_phase( ) calls adequately document each non-interactive code paragraph. |