Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created August 3, 2011 15:14
Show Gist options
  • Save seanparsons/1122882 to your computer and use it in GitHub Desktop.
Save seanparsons/1122882 to your computer and use it in GitHub Desktop.
Quick example of a payment process done with Akka.
import akka.actor._
import akka.actor.Actor._
case class StartPayment(provider: String)
case class CompletePayment(provider: String)
case class PaymentProcess(userId: Int) extends Actor {
var currentProvider: String = _
def receive = {
case StartPayment(provider) => {
currentProvider = provider
println("Start payment: " + provider)
}
case CompletePayment(provider) => {
if (currentProvider == provider) println("Successfully completed payment with " + provider)
else println("You're doing it wrong.")
currentProvider = null
}
}
}
val user1PaymentActor = actorOf(new PaymentProcess(1)).start()
user1PaymentActor ! StartPayment("Bank Awesome"); user1PaymentActor ! CompletePayment("Dave's Bank"); user1PaymentActor ! StartPayment("Bank Awesome"); user1PaymentActor ! CompletePayment("Bank Awesome")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment