Last active
August 29, 2015 14:01
-
-
Save tabdulradi/cbc5f95b33b430edcbc5 to your computer and use it in GitHub Desktop.
This file contains 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
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