I have a method that is supposed to go over a Future and return a Tuple. Here it is:
private def myMethod(id: Long): Future[(Double, Double)] = {
val result = for {
someValue <- run { getFromDb(id).headOption }
value <- someValue
} yield {
value.valueType match {
case ValueType.TypeA => (1.0, 1.0)
case ValueType.TypeB => (2.0, 2.0)
}
}
}
Here is my run method:
private def run[R](dbio: slick.dbio.DBIOAction[R, slick.dbio.NoStream, scala.Nothing]) = async {
await(db.run(dbio))
}
It uses the Scala Async library to time my calls to the database!
the getFromDB method is just doing a query:
def getFromDb(myId: Long) {
MyTableQuery.filter(_.id === myId)
}
It complaints that myMethod returns a Future[Nothing]. I do not see any problems here. Any clues as to what might not satisfy the return type that I'm looking for?
async {await(db.run(dbio))}
the same as justdb.run(dbio)
? – Régis Jean-Gillesrun
? Because your are flatMapping over the return value once more, suggesting that you have something like aFuture[Future[T]]
as a return value, which seems odd. – Régis Jean-GillesR
is thus inferred fromgetFromDb
, whose definition is also missing. Please post a complete snippet. – Régis Jean-Gilles