slick-3.0

When does slick start the transaction if the DBIO begins with a future?


Let's say there's a DBIO composed of a Future and a DBIO, like:


/* Talks to some http service */
def httpFuture: Future[Unit] = ???

def addDbRow: DBIO[Unit] = MyTable += MyRow(1)

val db: DatabaseDef = ???

val dbio: DBIO[Unit] = for {
  _ <- DBIO.from(httpFuture())
  _ <- addDbRow()
} yield ()

db.run(dbio.transactionally)

Does Slick wait until after the future to begin the database transaction?


Solution

  • It looks like Slick does wait. If you set:

    def httpFuture: Future[Unit] = Future(Thread.sleep(10 * 1000)) // sleep for 10seconds
    

    and watch the database logs, you can see that the transaction does not begin until after the future completes.