Merge pull request #208 from ouchadam/bug/importing-keys-fails-first-time
Room key imports failing the first time
This commit is contained in:
commit
146e30193f
|
@ -14,6 +14,8 @@ import com.squareup.sqldelight.TransactionWithoutReturn
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
class OlmPersistence(
|
class OlmPersistence(
|
||||||
private val database: DapkDb,
|
private val database: DapkDb,
|
||||||
|
@ -83,11 +85,13 @@ class OlmPersistence(
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) {
|
suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) {
|
||||||
val scope = CoroutineScope(dispatchers.io)
|
val transaction = suspendCoroutine { continuation ->
|
||||||
database.cryptoQueries.transaction {
|
database.cryptoQueries.transaction {
|
||||||
scope.launch { action() }
|
continuation.resume(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
action(transaction)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun persist(sessionId: SessionId, inboundGroupSession: SerializedObject) {
|
suspend fun persist(sessionId: SessionId, inboundGroupSession: SerializedObject) {
|
||||||
withContext(dispatchers.io) {
|
withContext(dispatchers.io) {
|
||||||
|
|
Loading…
Reference in New Issue