From 23ba01509cea17d1526ee23ae2eb7e53eafba9e6 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 17 Oct 2022 23:05:13 +0100 Subject: [PATCH] fixing key imports failing the first time --- .../main/kotlin/app/dapk/st/domain/OlmPersistence.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/domains/store/src/main/kotlin/app/dapk/st/domain/OlmPersistence.kt b/domains/store/src/main/kotlin/app/dapk/st/domain/OlmPersistence.kt index c01d535..df3a63c 100644 --- a/domains/store/src/main/kotlin/app/dapk/st/domain/OlmPersistence.kt +++ b/domains/store/src/main/kotlin/app/dapk/st/domain/OlmPersistence.kt @@ -14,6 +14,8 @@ import com.squareup.sqldelight.TransactionWithoutReturn import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import kotlin.coroutines.resume +import kotlin.coroutines.suspendCoroutine class OlmPersistence( private val database: DapkDb, @@ -83,10 +85,12 @@ class OlmPersistence( } suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) { - val scope = CoroutineScope(dispatchers.io) - database.cryptoQueries.transaction { - scope.launch { action() } + val transaction = suspendCoroutine { continuation -> + database.cryptoQueries.transaction { + continuation.resume(this) + } } + action(transaction) } suspend fun persist(sessionId: SessionId, inboundGroupSession: SerializedObject) {