Skip to content

Commit 1e00cc7

Browse files
committed
Replace Duration.INFINITE by ZERO when awaiting JDA termination
1 parent 2c00259 commit 1e00cc7

File tree

1 file changed

+5
-2
lines changed
  • src/main/kotlin/io/github/freya022/botcommands/internal/core

1 file changed

+5
-2
lines changed

src/main/kotlin/io/github/freya022/botcommands/internal/core/BContextImpl.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import io.github.freya022.botcommands.api.core.utils.loggerOf
2121
import io.github.freya022.botcommands.internal.commands.application.ApplicationCommandsContextImpl
2222
import io.github.freya022.botcommands.internal.commands.text.TextCommandsContextImpl
2323
import io.github.freya022.botcommands.internal.core.service.SpringServiceContainer
24+
import io.github.freya022.botcommands.internal.utils.takeIfFinite
2425
import io.github.freya022.botcommands.internal.utils.unwrap
2526
import io.github.oshai.kotlinlogging.KotlinLogging
2627
import kotlinx.coroutines.CoroutineScope
@@ -247,6 +248,8 @@ internal class BContextImpl internal constructor(
247248
}
248249

249250
private fun awaitJDAShutdown(durationUntilDeadlineFn: () -> Duration): Boolean {
251+
fun Duration.finiteOrZero() = takeIfFinite() ?: Duration.ZERO
252+
250253
val jda = jdaOrNull
251254
if (jda == null) {
252255
logger.debug { "Not awaiting JDA shutdown as there is no JDA instance registered" }
@@ -255,12 +258,12 @@ internal class BContextImpl internal constructor(
255258
val shardManager = jda.shardManager
256259
if (shardManager != null) {
257260
shardManager.shards.forEach { shard ->
258-
if (!shard.awaitShutdown(durationUntilDeadlineFn())) {
261+
if (!shard.awaitShutdown(durationUntilDeadlineFn().finiteOrZero())) {
259262
return false
260263
}
261264
}
262265
} else {
263-
if (!jda.awaitShutdown(durationUntilDeadlineFn())) {
266+
if (!jda.awaitShutdown(durationUntilDeadlineFn().finiteOrZero())) {
264267
return false
265268
}
266269
}

0 commit comments

Comments
 (0)