Skip to content

Commit 21bf08b

Browse files
committed
Refactor jdbcSuspendTransaction to use newSuspendedTransaction for improved coroutine support
1 parent 3d70116 commit 21bf08b

File tree

1 file changed

+4
-11
lines changed
  • krescent-exposed/src/main/kotlin/dev/helight/krescent/exposed

1 file changed

+4
-11
lines changed
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package dev.helight.krescent.exposed
22

3-
import kotlinx.coroutines.Dispatchers
4-
import kotlinx.coroutines.async
53
import kotlinx.coroutines.coroutineScope
6-
import kotlinx.coroutines.runBlocking
74
import org.jetbrains.exposed.sql.Database
85
import org.jetbrains.exposed.sql.Transaction
96
import org.jetbrains.exposed.sql.transactions.TransactionManager
10-
import org.jetbrains.exposed.sql.transactions.transaction
7+
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
118

129
internal suspend fun <T> jdbcSuspendTransaction(
1310
database: Database,
@@ -19,11 +16,7 @@ internal suspend fun <T> jdbcSuspendTransaction(
1916
?.takeIf { it.db == database }
2017
?.let { return@coroutineScope statement.invoke(it) }
2118

22-
async(Dispatchers.IO) {
23-
transaction(database) {
24-
runBlocking {
25-
statement.invoke(this@transaction)
26-
}
27-
}
28-
}.await()
19+
return@coroutineScope newSuspendedTransaction(db = database) {
20+
statement.invoke(this@newSuspendedTransaction)
21+
}
2922
}

0 commit comments

Comments
 (0)