Created
January 22, 2020 11:33
-
-
Save msosnicki/0f07b66dd2fd2c3608fea736bf85ae9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ssn | |
import cats.effect.{Blocker, ExitCode, IO, IOApp} | |
import cats.implicits._ | |
import doobie.implicits._ | |
import doobie.hikari.HikariTransactor | |
import doobie.util.ExecutionContexts | |
import doobie.util.transactor.Transactor | |
import scala.concurrent.duration._ | |
object TimeoutProblem extends IOApp { | |
val url = "jdbc:postgresql://localhost:5432/my_db" | |
val user = "my_user" | |
val pass = "my_pass" | |
val transactor = for { | |
b <- Blocker[IO] | |
xa = Transactor | |
.fromDriverManager[IO]("org.postgresql.Driver",url,user,pass, b) | |
} yield xa | |
val hikariTransactor = for { | |
be <- Blocker[IO] | |
ce <- ExecutionContexts.fixedThreadPool[IO](16) | |
xa <- HikariTransactor.newHikariTransactor[IO]( | |
"org.postgresql.Driver", | |
url, | |
user, | |
pass, | |
ce, | |
be | |
) | |
} yield xa | |
override def run(args: List[String]): IO[ExitCode] = | |
transactor | |
.use(t => { | |
sql"select 42" | |
.query[Int] | |
.unique | |
.transact(t) | |
.timeout(2.seconds) | |
.attempt | |
.flatTap(e => IO(println(e))) | |
.as(ExitCode.Success) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment