From e0e72655ee0c503a4ef565f062bbf27da8d40792 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Wed, 27 Nov 2024 21:24:44 +0800 Subject: [PATCH] Make wrapping executing blocking Exposed statements in `Dispatchers.IO` not mandatory --- README.md | 8 ++++---- .../com/huanshankeji/exposedvertxsqlclient/Examples.kt | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fd5d416..9b12cf6 100644 --- a/README.md +++ b/README.md @@ -108,13 +108,13 @@ val tables = arrayOf(Examples) For example, to create tables: ```kotlin -withContext(Dispatchers.IO) { - databaseClient.exposedTransaction { - SchemaUtils.create(*tables) - } +databaseClient.exposedTransaction { + SchemaUtils.create(*tables) } ``` +If you execute blocking Exposed statements inside `Verticle`s or event loop threads that you shouldn't block, you should use Vert.x `Vertx.executeBlocking` or Coroutines `Dispatchers.IO`. + ### CRUD (DML and DQL) operations with `DatabaseClient` #### Core APIs diff --git a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt index d451c09..f0450e1 100644 --- a/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt +++ b/integrated/src/main/kotlin/com/huanshankeji/exposedvertxsqlclient/Examples.kt @@ -12,8 +12,6 @@ import com.huanshankeji.exposedvertxsqlclient.sql.* import io.vertx.core.Verticle import io.vertx.core.Vertx import io.vertx.sqlclient.SqlClient -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils @@ -52,10 +50,9 @@ suspend fun examples(vertx: Vertx) { val databaseClient = DatabaseClient(vertxSqlClient, exposedDatabase) - withContext(Dispatchers.IO) { - databaseClient.exposedTransaction { - SchemaUtils.create(*tables) - } + // put in `Vertx.executeBlocking` or `Dispatchers.IO` if needed + databaseClient.exposedTransaction { + SchemaUtils.create(*tables) } run {