Skip to content

Commit

Permalink
Make wrapping executing blocking Exposed statements in `Dispatchers.I…
Browse files Browse the repository at this point in the history
…O` not mandatory
  • Loading branch information
ShreckYe committed Nov 27, 2024
1 parent 0c5fe28 commit e0e7265
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e0e7265

Please sign in to comment.