From: TheSaminator Date: Mon, 14 Feb 2022 14:26:26 +0000 (-0500) Subject: Optimizations X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=de74393c7fab1e223a306f46891a06ea22d01e29;p=starship-fights Optimizations --- diff --git a/src/jvmMain/kotlin/starshipfights/data/data_routines.kt b/src/jvmMain/kotlin/starshipfights/data/data_routines.kt index 080a4d1..4c0d3ac 100644 --- a/src/jvmMain/kotlin/starshipfights/data/data_routines.kt +++ b/src/jvmMain/kotlin/starshipfights/data/data_routines.kt @@ -12,13 +12,14 @@ import starshipfights.game.AdmiralRank import starshipfights.sfLogger import java.time.Instant import java.time.ZoneId -import kotlin.coroutines.CoroutineContext -object DataRoutines : CoroutineScope { - override val coroutineContext: CoroutineContext = SupervisorJob() + CoroutineExceptionHandler { ctx, ex -> - val coroutine = ctx[CoroutineName]?.name?.let { "coroutine $it" } ?: "unnamed coroutine" - sfLogger.error("Caught unhandled exception in $coroutine", ex) - } +object DataRoutines { + private val scope: CoroutineScope = CoroutineScope( + SupervisorJob() + CoroutineExceptionHandler { ctx, ex -> + val coroutine = ctx[CoroutineName]?.name?.let { "coroutine $it" } ?: "unnamed coroutine" + sfLogger.error("Caught unhandled exception in $coroutine", ex) + } + ) fun initializeRoutines(): Job { // Initialize tables @@ -28,7 +29,7 @@ object DataRoutines : CoroutineScope { User.initialize() UserSession.initialize() - return launch { + return scope.launch { // Repair ships launch { while (currentCoroutineContext().isActive) { diff --git a/src/jvmMain/kotlin/starshipfights/server.kt b/src/jvmMain/kotlin/starshipfights/server.kt index 2285f9b..49c0c96 100644 --- a/src/jvmMain/kotlin/starshipfights/server.kt +++ b/src/jvmMain/kotlin/starshipfights/server.kt @@ -117,10 +117,12 @@ fun main() { call.response.header(HttpHeaders.ContentEncoding, CompressedFileType.GZIP.encoding) call.respondBytes(gzipContent.readBytes(), contentType) - } else - ResourceLoader.getResource(contentPath)?.let { call.respondBytes(it.readBytes(), contentType) } - } else - ResourceLoader.getResource(contentPath)?.let { call.respondBytes(it.readBytes(), contentType) } + + return@get + } + } + + ResourceLoader.getResource(contentPath)?.let { call.respondBytes(it.readBytes(), contentType) } } } }