Skip to content

Commit

Permalink
refactor: use guard clause in thread unlock logic
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Jan 24, 2024
1 parent 31920d0 commit 280e90e
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,29 @@ private void subscribe() {
}
}

private void onThreadUnlock(Throwable t) {
if (enabled) {
if (reconnected) {
plugin.log(Level.WARNING,
"Connection to the Redis server was lost. Attempting reconnection in 8 seconds...", t);
}
try {
this.unsubscribe();
} catch (Throwable ignored) {
// empty catch
}
private void onThreadUnlock(@NotNull Throwable t) {
if (!enabled) {
return;
}

// Make an instant subscribe if occurs any error on initialization
if (!reconnected) {
reconnected = true;
} else {
try {
Thread.sleep(RECONNECTION_TIME);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (reconnected) {
plugin.log(Level.WARNING, "Redis Server connection lost. Attempting reconnect in %ss..."
.formatted(RECONNECTION_TIME / 1000), t);
}
try {
this.unsubscribe();
} catch (Throwable ignored) {
// empty catch
}

// Make an instant subscribe if occurs any error on initialization
if (!reconnected) {
reconnected = true;
} else {
try {
Thread.sleep(RECONNECTION_TIME);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
Expand Down

0 comments on commit 280e90e

Please sign in to comment.