Skip to content

Instantly share code, notes, and snippets.

@lnramirez
Created January 19, 2016 15:36
Show Gist options
  • Select an option

  • Save lnramirez/6d47463d114fba8b56b7 to your computer and use it in GitHub Desktop.

Select an option

Save lnramirez/6d47463d114fba8b56b7 to your computer and use it in GitHub Desktop.
//ommited code
def receive = {
case aMessage =>
val aFuture = future(db.getConnection)
aFuture.map { theConn => //from previous line when you acquire the conn and when you execute the next line
//it could pass a long time they run in different threads/time
//that's why you should better create an actor that handles this sync and let
//akka do the async part
theConn.prepareStatemnt(someSQL)
//ommited code
}
}
//actor A receives,
//actor B proccess db (and have multiple instances of this one due to slownes from db)
class ActorA(routerOfB : ActorRef) extends Actor {
def recieve = {
case aMessage =>
routerOfB ! aMessage
}
}
class ActorB(db : DB) extends Actor {
def receive = {
case receive = {
val conn = db.getConnection //this blocks but we have multiple instances
//and enforces to run in same thread
val ps = conn.prepareStatement(someSQL)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment