Skip to content

Commit

Permalink
try {} finally {} pattern in Acquirable#sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Steanky committed Sep 6, 2023
1 parent 50b25fc commit a4e1d00
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/net/minestom/server/thread/Acquirable.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ default boolean isLocal() {
*/
default void sync(@NotNull Consumer<T> consumer) {
Acquired<T> acquired = lock();
consumer.accept(acquired.get());
acquired.unlock();
try {
consumer.accept(acquired.get());
} finally {
acquired.unlock();
}
}

/**
Expand Down

0 comments on commit a4e1d00

Please sign in to comment.