0

I know that Futures in Scala, when grouped in for comprehensions, run sequentially unless they are declared outside of the for comprehension (as this article explains). Do DBIOActions work the same way? e.g. in the following query, is query1 guaranteed to execute before query2?

db.run {
  for {
    result1 <- query1.result
    result2 <- query2.result
  } yield (result1, result2)
}
Will
  • 1
  • 1

1 Answers1

0

Yes! query1 is guaranteed to run before query2. Remember that the for comprehension is equivalent to:

query1.reult.flatMap(result1 => query2.result.map(result2 => (result1, result2))

and the docs for flatMap on DBIOAction states that "Use the result produced by the successful execution of this action to compute and then run the next action in sequence." http://slick.lightbend.com/doc/3.2.0/api/index.html#slick.dbio.DBIOAction@flatMap

AHonarmand
  • 530
  • 1
  • 8
  • 16