Skip to content

Instantly share code, notes, and snippets.

@Andrea
Created April 6, 2020 10:03
Show Gist options
  • Save Andrea/e886e241486fca56ba4d14a0fac6042d to your computer and use it in GitHub Desktop.
Save Andrea/e886e241486fca56ba4d14a0fac6042d to your computer and use it in GitHub Desktop.
Most of the config
```
//...
private val nThreads = Runtime.getRuntime.availableProcessors * 2
private val executorService = Executors.newFixedThreadPool(nThreads)
implicit val executionContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(executorService)
implicit val cs: ContextShift[IO] = IO.contextShift(ec)
implicit val timer: Timer[IO] = IO.timer(ec)
//Here we do a query using doobie
val domainRoutes: HttpRoutes[IO] = DomainRoutes.routes(..., ...)
val httpApp = Router(
"/" -> (domainRoutes)
).orNotFound
BlazeServerBuilder[IO]
.bindHttp(port, host)
.withExecutionContext(ec)
.withWebSockets(false)
.withHttpApp(httpApp)
.resource
///somewhere else this is how we create the transactor, we use a Blocker[IO]
def transactorFrom(config: Db)(implicit be: Blocker): Resource[IO, HikariTransactor[IO]] = {
HikariTransactor.newHikariTransactor[IO](
config.driver,
config.url,
config.user,
config.password,
ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(10)),
be
)
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment