diff options
author | perlancar (on netbook-dell-xps13) <perlancar@gmail.com> | 2020-07-09 15:54:29 +0700 |
---|---|---|
committer | perlancar (on netbook-dell-xps13) <perlancar@gmail.com> | 2020-07-09 15:54:29 +0700 |
commit | 61e5344f20d7f1c2524ead681e26473baf19630e (patch) | |
tree | 0a3ec6b0f087ec9713a85e6ad6eff7ecd58e6223 | |
parent | 744bac910e6e99cfd0e6278455d45b9c7322504b (diff) |
Add optional argument 'force_update' to update()
-rw-r--r-- | lib/Progress/Any.pm | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/Progress/Any.pm b/lib/Progress/Any.pm index e8dfdcc..372552c 100644 --- a/lib/Progress/Any.pm +++ b/lib/Progress/Any.pm @@ -359,7 +359,10 @@ sub _should_update_output { # finishing, update the output to show finished state return 1; } elsif ($output->{force_update}) { - # force update + # this is an undocumented force update for now, the output itself or + # something else can set this to force an update. but this will only be + # done once because we delete the key; if another update wants to be + # forced, they need to set this again. delete $output->{force_update}; return 1; } elsif ($priority eq 'high') { @@ -393,6 +396,7 @@ sub update { my $message = delete($args{message}); my $priority = delete($args{priority}) // 'normal'; + my $force_update = delete($args{force_update}); die "Unknown argument(s) to update(): ".join(", ", keys(%args)) if keys(%args); @@ -405,7 +409,8 @@ sub update { while (1) { if ($outputs{$task}) { for my $output (@{ $outputs{$task} }) { - next unless $self->_should_update_output($output, $now, $priority); + next unless $force_update || + $self->_should_update_output($output, $now, $priority); if (ref($message) eq 'CODE') { $message = $message->(); } @@ -895,6 +900,11 @@ ignore updates lower than a certain level. Can be set to C<finished> to finish a task. +=item * force_update => BOOL + +Default false. Some outputs choose only to update themselves after a certain +amount of time or number of updates have passed; this forces their update. + =back =head2 finish |