Optimizations
authorTheSaminator <TheSaminator@users.noreply.github.com>
Mon, 14 Feb 2022 14:26:26 +0000 (09:26 -0500)
committerTheSaminator <TheSaminator@users.noreply.github.com>
Mon, 14 Feb 2022 14:26:26 +0000 (09:26 -0500)
src/jvmMain/kotlin/starshipfights/data/data_routines.kt
src/jvmMain/kotlin/starshipfights/server.kt

index 080a4d15edb0a4efefc8e918ccd056decadb58cd..4c0d3ac18da5475aa7e7cbfa32b72e4bcc190de0 100644 (file)
@@ -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) {
index 2285f9b96f2406c236de9636391552532151882a..49c0c9665ca8d96b2efc39bac80173f028795dfe 100644 (file)
@@ -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) }
                                }
                        }
                }