providing dedicated scope instead of forcing transaction callback to suspend
This commit is contained in:
parent
4e3da03062
commit
d05d86a02d
|
@ -53,7 +53,6 @@ class OlmWrapper(
|
||||||
true -> OlmInboundGroupSession.importSession(it.sessionKey)
|
true -> OlmInboundGroupSession.importSession(it.sessionKey)
|
||||||
false -> OlmInboundGroupSession(it.sessionKey)
|
false -> OlmInboundGroupSession(it.sessionKey)
|
||||||
}
|
}
|
||||||
logger.crypto("import megolm ${it.sessionKey}")
|
|
||||||
olmStore.persist(it.sessionId, inBound)
|
olmStore.persist(it.sessionId, inBound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ import app.dapk.st.matrix.common.Curve25519
|
||||||
import app.dapk.st.matrix.common.RoomId
|
import app.dapk.st.matrix.common.RoomId
|
||||||
import app.dapk.st.matrix.common.SessionId
|
import app.dapk.st.matrix.common.SessionId
|
||||||
import com.squareup.sqldelight.TransactionWithoutReturn
|
import com.squareup.sqldelight.TransactionWithoutReturn
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
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,13 +83,9 @@ class OlmPersistence(
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) {
|
suspend fun startTransaction(action: suspend TransactionWithoutReturn.() -> Unit) {
|
||||||
val transaction = suspendCoroutine {
|
val scope = CoroutineScope(dispatchers.io)
|
||||||
database.cryptoQueries.transaction(false) {
|
database.cryptoQueries.transaction {
|
||||||
it.resume(this)
|
scope.launch { action() }
|
||||||
}
|
|
||||||
}
|
|
||||||
dispatchers.withIoContext {
|
|
||||||
action(transaction)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue