Skip to content

Instantly share code, notes, and snippets.

@tabdulradi
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabdulradi/cbc5f95b33b430edcbc5 to your computer and use it in GitHub Desktop.
Save tabdulradi/cbc5f95b33b430edcbc5 to your computer and use it in GitHub Desktop.
import akka.actor._
class FibonacciGenerator extends Actor {
import FibonacciGenerator._
def receive = fib()
def fib(a: Long = 0, b: Long = 1): Receive = {
case Next =>
val c: Long = a + b
sender ! c
context.become(fib(b, c))
}
}
object FibonacciGenerator {
case object Next
}
object Main extends App {
import FibonacciGenerator._
import ActorDSL._
implicit val system = ActorSystem("test")
val fib = system.actorOf(Props[FibonacciGenerator])
actor(new Act {
whenStarting { fib ! Next }
become {
case x: Long if x < 9999999999L =>
println(x)
fib ! Next
case x =>
println(x)
println("Bye")
system.shutdown
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment