openepaperlink: handle concurrent revbank instances better

RevBank reads the new products file on every interaction (e.g. pressing
enter), and then fires hooks like `product_changed`. Every running
instance gets those hooks, but the price tage should be generated only
once.
This commit is contained in:
Juerd Waalboer 2025-01-04 21:56:54 +01:00
parent 35fd5f4d85
commit 5d910510b8
3 changed files with 46 additions and 16 deletions

View file

@ -64,7 +64,8 @@ sub release_all_locks() {
}
sub with_lock :prototype(&) ($code) {
get_lock;
my $skip = $ENV{REVBANK_SKIP_LOCK};
get_lock unless $skip;
my @rv;
my $rv;
my $list_context = wantarray;
@ -72,7 +73,7 @@ sub with_lock :prototype(&) ($code) {
@rv = $code->() if $list_context;
$rv = $code->() if not $list_context;
};
release_lock;
release_lock unless $skip;
croak $@ =~ s/\.?\n$/, rethrown/r if $@;
return @rv if $list_context;
return $rv if not $list_context;