Skip to content

Instantly share code, notes, and snippets.

@pellekrogholt
Created December 14, 2013 15:26
Show Gist options
  • Save pellekrogholt/7960532 to your computer and use it in GitHub Desktop.
Save pellekrogholt/7960532 to your computer and use it in GitHub Desktop.
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