Reputation: 430
Hi I'm so confuse on Slick 3, I have create simple insert. If I have insert new PK, It's working well but when I tried insert an exist PK, Slick don't throw any error and future.isCompleted is still return true. So What wrong of my code?
val db = Database.forConfig("db")
val future = {
try {
val insert = DBIO.seq(
subscribers += subscriber
)
db.run(insert.transactionally)
} finally db.close
}
return if (future.isCompleted) return Some(subscriber) else None
Solved: I Just have to Await the result.
val db = Database.forConfig("db")
val isCompleted = {
val f = db.run((subscribers += subscriber).transactionally)
try {
Await.result(f, Duration.Inf)
true
} catch {
case _ => false
} finally db.close
}
return if (isCompleted) return Some(subscriber) else None
Upvotes: 0
Views: 265
Reputation: 3081
The problem seems to be that your code does not wait till the future db.run(insert.transactionally)
finishes. You create the future and then immediately close the db.
Upvotes: 1