Skip to content

Commit

Permalink
use blocking executor for awaiting connections. (zio#6803)
Browse files Browse the repository at this point in the history
  • Loading branch information
khajavi authored May 16, 2022
1 parent 0c6c907 commit 52c822f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions docs/howto/interop/with-cats-effect.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ Let's try doing that in each of which:

#### Customized Transactor (CE2)

ZIO provides a specific blocking thread pool for blocking operations. The `doobie-hikari` module helps us create a transactor with two separated executors, one for blocking operations like JDBC operations, and the other one for non-blocking operations like performing awaiting connections to the database. So we shouldn't run blocking JDBC operations on the main thread pool.
ZIO provides a specific blocking thread pool for blocking operations. The `doobie-hikari` module helps us create a transactor with two separated executors, one for blocking operations, and the other one for non-blocking operations. So we shouldn't run blocking JDBC operations or perform awaiting connections to the database on the main thread pool.

So let's fix this issue in the previous example. In the following snippet we are going to create a `ZMHikari` of Hikari transactor. In this example we are using `0.13.4` version of doobie which supports CE2:

Expand All @@ -575,15 +575,14 @@ import zio.interop.catz._

def transactor: ZManaged[Blocking, Throwable, HikariTransactor[Task]] =
for {
rt <- ZIO.runtime[Any].toManaged_
be <- zio.blocking.blockingExecutor.toManaged_ // our blocking EC
xa <- HikariTransactor
.newHikariTransactor[Task](
"org.h2.Driver", // driver classname
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", // connect URL
"sa", // username
"", // password
rt.platform.executor.asEC, // await connection here
be.asEC, // await connection here
Blocker.liftExecutionContext(be.asEC) // execute JDBC operations here
)
.toManagedZIO
Expand Down

0 comments on commit 52c822f

Please sign in to comment.