Given the following example:
val handler : Connection = new DatabaseConnectionHandler()
val result : Future[Future[Future[Option[ResultSet]]]] = handler.connect
.map( (parameters) => handler )
.map( connection => connection.sendQuery("BEGIN TRANSACTION SERIALIZABLE") )
.map( future => future.map( query => query.rows ) )
.map( future => handler.sendQuery("COMMIT").map( query => future ) )
Is it possible to flatten it to receive a Future[Option[ResultSet]]
at the end instead of this future inside a future inside a future structure in Scala?
I am currently using Scala's 2.10 Future's and Promise's, but I can't find a way to to this. I know I can use nested callbacks but I would rather avoid that since the code is going to look horrible.
The Connection
trait is defined here.