Skip to content

Instantly share code, notes, and snippets.

@michalkowol
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save michalkowol/9ae423ab2c44f28933f3 to your computer and use it in GitHub Desktop.

Select an option

Save michalkowol/9ae423ab2c44f28933f3 to your computer and use it in GitHub Desktop.
class WrongWayActor extends Actor {
override def receive: Receive = {
case _ => Future {
val result = doSomeHeavyComputation
sender() ! result // if you reacive other message in meantime, it will send the response to WRONG actor
}
}
}
class GoodWayActor extends Actor {
override def receive: Receive = {
case _ =>
val originalSender = sender()
Future {
val result = doSomeHeavyComputation
originalSender ! result // it closes clouser over - it will send response to right actor
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment