Make sure lock is free'd even on error (fixes #3116)

This commit is contained in:
SirYwell
2021-08-23 10:05:38 +02:00
parent a8fc6662e0
commit 6ec136a03d
2 changed files with 43 additions and 5 deletions

View File

@ -71,11 +71,9 @@ public final class LockRepository {
* @param runnable Action to run when the lock is available
*/
public void useLock(final @NonNull LockKey key, final @NonNull Runnable runnable) {
this.useLock(key, lock -> {
lock.lock();
runnable.run();
lock.unlock();
});
try (LockAccess ignored = lock(key)) {
runnable.run();
}
}
/**