Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
bar
or the subclass bar
is irrelevant insofar as the superclass can observe.
Hi everyone,
I'm trying to perform a database transaction and pass the DB connection around multiple operations that are executed in Future
s and my database connection seems to "escape" the scope and close before my Future
could finish. I found a bunch of sites (namely Slick's github) discussing the matter and how hard it is to mix transactions and futures/asynchrony, none of which seemed to have a solution. I figured I'd try my luck and see if perhaps one of you ever figured a solution to this. This is my code:
val result: Future[Unit] = db.withTransaction { implicit conn: Connection =>
for {
_ <- step1(product.id, baseFields)(conn) // Future[Unit]
_ <- step2(product, dto)(conn) // Future[Unit]
} yield ()
} // This finishes executing before the future resulting from step1 and step2 is completed
// ... `result` is then eventually handled by the Play Framework
Note: I'm not using a database abstraction library and I'm using JDBC directly.