Skip to content

Commit

Permalink
don't have to check urgent mode when starting saving task
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jan 6, 2025
1 parent a347174 commit 58c145c
Showing 1 changed file with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import me.hsgamer.topper.storage.core.DataStorage;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -66,24 +65,16 @@ private void save(boolean urgent) {
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

Runnable saveTask = () -> {
try {
storage.save(finalMap);
if (!removeKeys.isEmpty()) {
storage.remove(removeKeys);
}
savingMap.set(null);
} catch (Throwable t) {
logger.log(Level.SEVERE, "Failed to save entries for " + holder.getName(), t);
} finally {
saving.set(false);
try {
storage.save(finalMap);
if (!removeKeys.isEmpty()) {
storage.remove(removeKeys);
}
};

if (urgent) {
saveTask.run();
} else {
CompletableFuture.runAsync(saveTask);
savingMap.set(null);
} catch (Throwable t) {
logger.log(Level.SEVERE, "Failed to save entries for " + holder.getName(), t);
} finally {
saving.set(false);
}
}

Expand Down

0 comments on commit 58c145c

Please sign in to comment.