In this example an Execution Context is used to process the future.
Why is this used when Scalike has a built in connection pool?
Shouldn't the Future use one of the pool threads to execute? It seems like a real waste to ForkJoin a thread just to wait on the Future while another thread does the IO work.
http://scalikejdbc.org/documentation/transaction.html
object FutureDB {
implicit val ec = myOwnExecutorContext
def updateFirstName(id: Int, firstName: String)(implicit session: DBSession): Future[Int] = {
Future {
blocking {
session.update("update users set first_name = ? where id = ?", firstName, id)
}
}
}
def updateLastName(id: Int, lastName: String)(implicit session: DBSession): Future[Int] = {
Future {
blocking {
session.update("update users set last_name = ? where id = ?", lastName, id)
}
}
}
}
object Example {
import FutureDB._
val fResult = DB futureLocalTx { implicit s =>
updateFirstName(3, "John").map(_ => updateLastName(3, "Smith"))
}
}
Example.fResult.foreach(println(_))