diff --git a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt index 105f99aab..9dfdeedb8 100644 --- a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt +++ b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/job/StatusBackend.kt @@ -2,21 +2,22 @@ package org.worldcubeassociation.tnoodle.server.job import io.ktor.websocket.* import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch sealed class StatusBackend { - abstract suspend fun onProgress(worker: String) + abstract fun onProgress(worker: String) class JobRegistry(val jobId: Int) : StatusBackend() { - override suspend fun onProgress(worker: String) = JobSchedulingHandler.registerProgress(jobId, worker) + override fun onProgress(worker: String) = JobSchedulingHandler.registerProgress(jobId, worker) } - data object NoOp : StatusBackend() { - override suspend fun onProgress(worker: String) {} + object NoOp : StatusBackend() { + override fun onProgress(worker: String) {} } class Websocket(val socket: WebSocketSession) : StatusBackend(), CoroutineScope by socket { - override suspend fun onProgress(worker: String) { - socket.send(worker) + override fun onProgress(worker: String) { + launch { socket.send(worker) } } } } diff --git a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt index e8b710860..9e9b31c2b 100644 --- a/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt +++ b/server/src/main/kotlin/org/worldcubeassociation/tnoodle/server/routing/WcifHandler.kt @@ -5,7 +5,6 @@ import io.ktor.server.application.* import io.ktor.server.request.* import io.ktor.server.routing.* import io.ktor.websocket.* -import kotlinx.coroutines.runBlocking import kotlinx.serialization.encodeToString import org.worldcubeassociation.tnoodle.server.RouteHandler import org.worldcubeassociation.tnoodle.server.serial.JsonConfig @@ -54,7 +53,7 @@ class WcifHandler(val environmentConfig: ServerEnvironmentConfig) : RouteHandler override suspend fun ScramblingJobData.compute(statusBackend: StatusBackend): Pair { val wcif = WCIFScrambleMatcher.fillScrambleSetsAsync(request.wcif) { evt, _ -> - runBlocking { statusBackend.onProgress(evt.id) } + statusBackend.onProgress(evt.id) } return scrambledToResult(this, wcif, statusBackend)