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
User.initialize()
UserSession.initialize()
- return launch {
+ return scope.launch {
// Repair ships
launch {
while (currentCoroutineContext().isActive) {
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) }
}
}
}