I have the following singleton object which has a static method called connect which returns a DB connection. In classical synchronous programming I am understood to believe that you only ever want one instance of a connection however this seems at odds with the asynchronous model of the reactiveMongo driver which uses an underlying the Actor (Akka) model.
object MyMongoDriver {
def connect(uri: String) {
val driver = new MongoDriver
val connection: Try[MongoConnection] =
MongoConnection.parseURI(uri).map {
parsedURI => driver.connection(parsedURI)
}
}
}
What seems to be happening to me though is that one instance of MyMongoDriver is instantiated, and then multiple (as many as needed) connections are returned each time connect is called? I don't think I just introduced blocking, or have I? The rest of the asynchronous behavior I suspect continues to happen by design given reactivemongo is reactive. Is there a better way to handle connections?