Last active
August 29, 2015 14:10
-
-
Save michalkowol/9ae423ab2c44f28933f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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