Skip to content

Commit

Permalink
refactor: Put reconnect action mutex unlock inside finally block
Browse files Browse the repository at this point in the history
  • Loading branch information
pandier committed Apr 16, 2024
1 parent 455c35a commit a09b93e
Showing 1 changed file with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,31 @@ class ReconnectAction : DumbAwareAction() {
if (!mutex.tryLock())
return@launch

@Suppress("UnstableApiUsage")
withBackgroundProgress(project, "Reconnecting Discord client", false) {
try {
discordService.reconnect().await()

NotificationGroupManager.getInstance()
.getNotificationGroup("io.github.pandier.intellijdiscordrp.notification.Reconnecting")
.createNotification("Reconnected with Discord client", "", NotificationType.INFORMATION)
.notify(project)
} catch (ex: Exception) {
DiscordRichPresencePlugin.logger.warn("Failed to reconnect with Discord client", ex)
NotificationGroupManager.getInstance()
.getNotificationGroup("io.github.pandier.intellijdiscordrp.notification.Reconnecting")
.createNotification(
"Failed to reconnect with Discord client",
ex.message ?: "",
NotificationType.ERROR
)
.notify(project)
try {
@Suppress("UnstableApiUsage")
withBackgroundProgress(project, "Reconnecting Discord client", false) {
try {
discordService.reconnect().await()

NotificationGroupManager.getInstance()
.getNotificationGroup("io.github.pandier.intellijdiscordrp.notification.Reconnecting")
.createNotification("Reconnected with Discord client", "", NotificationType.INFORMATION)
.notify(project)
} catch (ex: Exception) {
DiscordRichPresencePlugin.logger.warn("Failed to reconnect with Discord client", ex)
NotificationGroupManager.getInstance()
.getNotificationGroup("io.github.pandier.intellijdiscordrp.notification.Reconnecting")
.createNotification(
"Failed to reconnect with Discord client",
ex.message ?: "",
NotificationType.ERROR
)
.notify(project)
}
}
} finally {
mutex.unlock()
}

mutex.unlock()
}
}
}

0 comments on commit a09b93e

Please sign in to comment.