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

69 Views Asked by At

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?

1

There are 1 best solutions below

0
sttawm On BEST ANSWER

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.