Created
December 14, 2013 15:26
-
-
Save pellekrogholt/7960532 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
package week12 | |
import akka.actor.Actor | |
import akka.actor.Props | |
import akka.event.LoggingReceive | |
class TransferMain extends Actor { | |
val accountA = context.actorOf(Props[BankAccount], "accountA") | |
val accountB = context.actorOf(Props[BankAccount], "accountB") | |
accountA ! BankAccount.Deposit(100) | |
def receive = LoggingReceive { | |
case BankAccount.Done => transfer(150) | |
} | |
def transfer(amount: BigInt): Unit = { | |
val transaction = context.actorOf(Props[WireTransfer], "transfer") | |
transaction ! WireTransfer.Transfer(accountA, accountB, amount) | |
context.become(LoggingReceive { | |
case WireTransfer.Done => | |
println("success") | |
context.stop(self) | |
case WireTransfer.Failed => | |
println("failed") | |
context.stop(self) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment